-->
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.  [ 1 post ] 
Author Message
 Post subject: Override equals() and hashcode() when using a composite key?
PostPosted: Tue Nov 23, 2004 12:47 pm 
Newbie

Joined: Sun Nov 21, 2004 6:20 pm
Posts: 11
Hi,

I am new to Hibernate and the reference paper does not really help me....at least I am unsure...

Here is my concrete example:
Table Question
question_id (pk)
question_text

Table Option
option id (pk)
question_id (pk, fk)
option_text

**********************
I have modelled this in java with the help of a third class (composite-class), that encapsulates the primary key for Option...

...now I read in the reference that -when using composite ids- one has
to override the equals() and the hashCode() methods...

Now my Question:
1. Which of the classes has to overwrite these methods?? The (non-persistent) Helper-class or the (persistent) Options-class??

2.) According to the reference I must not compare the identifyer values (these would be question_id+option_id)....instead one shall compare a "natural candidate key" - so, the only choice can be option_text in this case, which would mean, that equals() has to be overwritten only in the Options-class.....IS THAT RIGHT???....


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

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.