-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can't hibernate enhance equals/hashcode() too?
PostPosted: Thu May 27, 2004 11:33 am 
Newbie

Joined: Thu May 20, 2004 8:40 pm
Posts: 4
I have read the article from wiki and ,
the this way of implementing equals and hashcode() is
really weird.
Can't hibernate enhance equals/hashcode() too?
say , when add 2 new instance in session,
hibernate compare them with instance equality,
when 2 detached compared,or 1 detached instance with
1 instance loaded in session,
hibernate can compare them with orig ID(
hibernate may enhance out a new field ,say ,$origID,
and when instance detached, save origID in it).

Is that too hard or do i miss something?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 11:35 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate has nothing to do with equals() and hashCode().

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 12:16 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Also, you *do* miss something, namely: it doesn't work to change the rules you use for equals(). Because the contract is that two things that are equals() must also have the same hashCode(). So if you change the behavior of equals(), you must also change the behavior of hashCode().

But if you are changing your equals() rules based on BOTH objects that you are comparing, then there is no way to know what your rules for hashCode() should be!

Basically, you can't do the kind of situational comparison you want, since most of the time you aren't actually comparing anything -- you're just generating a hashcode based on one individual object.

Cheers,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 3:04 am 
Newbie

Joined: Thu May 20, 2004 8:40 pm
Posts: 4
oh,I get it.
Then i'm thinking another way of solving this problem,
to those entities who need be used in set, can use dual id
to solve this problem.
private long dualID;
// generate at new() using uuid.hex, and save it in database.
then use this dualID for identity comparing in Set.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.