-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to think about equals()
PostPosted: Thu May 06, 2004 7:51 pm 
Beginner
Beginner

Joined: Tue Sep 30, 2003 4:16 pm
Posts: 33
Thinking about exactly how to write the equals function for hibernate based classes....

I read somewhere to think of it kind of like a weaker database primary key. So for example, if the object was a Person, then I might make equals() be true if both the firstName and lastName properties were equal. In a way I am saying that this is how I decide that the objects are referring to the same person...

Therefore, other properties of the Person object, like salary or age would not have to be equal, and still two Person objects would be considered equal in Hibernate's view.

Is this correct? Because it is very different (I believe) from what equals means in POJOs where the two objects would NOT be considered the same.

I hope I explained the question well. Picking the right Properties is crucial with Hibernate so it's important to grok these subtleties...

Pito


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 2:11 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is mostly correct, although I would include some better natural keys, like the firstName, lastName, birthDate and lastLogin. This all has _nothing_ to do with Hibernate. There is no Hibernate code in equals(). There is nothing Hibernate changes.

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


Top
 Profile  
 
 Post subject: Last Login?
PostPosted: Fri May 07, 2004 9:31 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 4:16 pm
Posts: 33
Wait, you would include Last Login?

Well you certainly would never include Last Login on a database primary key.

That was exactly my point. The difference between equals for Hibernate and equals in general.

Can anyone clarify further?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 9:34 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hm, you are right, last login wasn't good.

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


Top
 Profile  
 
 Post subject: equals
PostPosted: Sat May 08, 2004 2:03 pm 
Regular
Regular

Joined: Sat Feb 21, 2004 8:54 pm
Posts: 60
Location: Lakewood, California
there is the thread: http://forum.hibernate.org/viewtopic.php?t=928172 that discusses this.

_________________
<http://tayek.com/>, co-chair <http://www.ocjug.org/>, actively
seeking telecommuting work. hate spam?
<https://www1.ietf.org/mailman/listinfo/asrg>


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