-->
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: Unique instance per session and equals/hashCode problems
PostPosted: Thu Sep 20, 2012 4:59 am 
Newbie

Joined: Wed Sep 19, 2012 7:42 am
Posts: 2
We have entities that don't implement equals and hashCode since hibernate doesn't recommends this. Hibenate promises to only have one instance of entity of same type and id per session. This suggests that, when enities are retrived by hibernate, calling equals on entity of type A and id 1 will return true if called by entity of same type and id. If my thinking is wrong please correct me. If not, here is the case, that this does't work (everything is happening in same session).

Entity model: A references a collection of Bs by @OneToMany association. A and B are abstract classes with joined subclasses (InheritanceType.JOINED)

Scenario:
1. load B with id=1 => returns proxy of B
2. load A with id=1 => returns proxy of A with noninitialized PersistentSet of Bs
3. call getter for Bs on A => initializes PersistentSet of Bs and that persistent set contains real entities and not proxies (including B with id=1)
4. calling equals on B from step 1. with B from step 3. (the one with id=1) will always return false

Proxy of B from step 1. points to same B from step 3.

As much as I understand, the collections will not work without overriding equals and hashCode. But overriding equals and hashCode triggers select when entities are put to HashMaps and HashSets, which we would like to avoid. Is there somethig we don't do right?


Top
 Profile  
 
 Post subject: Re: Unique instance per session and equals/hashCode problems
PostPosted: Fri Sep 28, 2012 5:54 am 
Newbie

Joined: Wed Sep 19, 2012 7:42 am
Posts: 2
No reply?


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.