-->
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.  [ 3 posts ] 
Author Message
 Post subject: Request for clarification on page 125 in HIA (2nd printing)
PostPosted: Wed Mar 01, 2006 11:03 am 
Newbie

Joined: Wed Feb 22, 2006 5:53 pm
Posts: 4
The discussion of equals() and hashCode() in the next-to-last paragraph on page 125 is either unclear. It reads:

Quote:
You might have noticed that the equals() and hashCode() methods always access the properties of the other object via the getter methods.


However, the code sample provided above on the same page clearly does not use a getter method in the implementation of hashCode().

Is the code sample wrong? Or is the statement wrong? The paragraph continues by saying "This is important, since the object instance passed as other might be a proxy object, not the actual instance that holds the persistent state" which could lead one to believe that getter methods aren't really required for hashCode() (since there obviously is no other instance passed to hashCode()).

What's the right thing to do for hashCode()?


Top
 Profile  
 
 Post subject: Request for clarification on page 125 in HIA (2nd printing)
PostPosted: Thu Mar 02, 2006 2:13 pm 
Newbie

Joined: Tue Jan 31, 2006 8:20 pm
Posts: 2
Quote:
You might have noticed that the equals() and hashCode() methods always access the properties of the other object via the getter methods.


It is just important to reference the OTHER object via getter.

In the case of the example on page 125 the hashCode method has no such access (hashCode never has such an access since only the this reference is available). In case of the equals method the example accesses the other property with that.getUsername() which is the correct way.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 2:23 pm 
Newbie

Joined: Wed Feb 22, 2006 5:53 pm
Posts: 4
Right, that much I understand. If that's all there is to it, then the statement should be changed to read:

Quote:
You might have noticed that the equals() method always accesses the properties of the other object via the getter methods.


My confusion about hashCode() comes from my lack of knowledge about Hibernate proxies. I wasn't sure whether Hibernate creates a subclass which doesn't override hashCode() but does override the getters. If that's the case, then I could understand the argument to use getters in hashCode() (and everywhere in equals(), not just for the other object).


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