-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Best practice? Lazy collection in equals()/hashCode()
PostPosted: Wed Oct 20, 2010 9:33 am 
Beginner
Beginner

Joined: Mon Mar 14, 2005 4:16 pm
Posts: 27
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,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.