frodeh wrote:
For instace if the setter-method of the lazy-property uses any value, the lazy-init triggers immideately.
I had a similar problem where I wanted the property to be a SortedSet. I then coded the setter like this :
Code:
public void setChildren(Set children){
if (children != null) {
this.children = new TreeSet(children);
}
}
This made all clidren to be loaded immideately, no matter if the hibernate-mapping said lazy or not....
Don't do that, the getter should return the instance provided by the setter or Hibernate will treat it as a new Collection with new children. This is clearly stated in the docs: what you're doing is called derefencing the collection. Hibernate uses its own implementation of the standard Collection interfaces, so you can't use your own implementation class. Just stick to using the interface. If you want the collection to be ordered, use a List or adjust your mapping (I think Hibernate supports sorted sets, but don't know how exactly from the top of my head).
Joris