Hi,
We have a few classes from our legacy app that uses lazy-loaded collections in their equals/hashCode methods. I have read that this is bad practice as the state of this classes could mutate. However, it was working fine in Hibernate 3.2.6 without issues and now with the newer 3.5/3.6 we get an
org.hibernate.AssertionFailure: collection [...] was not processed by flush()
Indeed, during flush the hashCode method is called and probably some lazy loaded collection is not loaded.
In our domain it makes sense to have this collections as part of what makes an object equals. For instance, one of such collections is a list of cross-references and two objects are different if that list is different (for instance, one has an additional cross-reference).
What would you do in this case? Any better practices you recommend? Removing those collections from the equals/hashcode is not that straightforward... is it the only solution? How are others dealing with similar scenarios?
Thanks in anticipacion,
|