-->
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.  [ 2 posts ] 
Author Message
 Post subject: hashCode and equals with LinkedHashSet and relationship
PostPosted: Tue Nov 10, 2009 1:30 am 
Regular
Regular

Joined: Wed Jan 21, 2009 8:41 pm
Posts: 54
The other day we had a problem whereby we had a parent and child object and the implementation of the child's hashcode method used the parents hashcode + the childs hashcode

well the problem lie in the fact that when the parent and child were eagerly loaded and then later the parents state was changed and some code that wanted to find the children in the parents linked hashset couldn't because the hashcode when the lookup was performed had changed from when the data was originally fetched and put in the map.

So I guess the lesson is that you shouldn't tie the child and parent's hashcode's if you're expecting to lookup the children in map after the parents state has changed such that it produces a different hashcode value.


Top
 Profile  
 
 Post subject: Re: hashCode and equals with LinkedHashSet and relationship
PostPosted: Tue Nov 10, 2009 5:30 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
The hashcode should never change during the lifetime of an object!
More about how to implement hahcode: http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#persistent-classes-equalshashcode

_________________
-----------------
Need advanced help? http://www.viada.eu


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

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.