Hi,
Can anybody guide me in overriding the hashcode() method in my PK class, if my composite key consists of a String, int and a boolean variable.
Thanks & Regards,
Vishal
-
Composite Key in Entity Bean (2 messages)
- Posted by: Vishal Revankar
- Posted on: July 22 2004 09:57 EDT
Threaded Messages (2)
- Composite Key in Entity Bean by Senthil Chinnaiyan on July 22 2004 11:20 EDT
- Composite Key in Entity Bean by Vishal Revankar on July 23 2004 01:00 EDT
-
Composite Key in Entity Bean[ Go to top ]
- Posted by: Senthil Chinnaiyan
- Posted on: July 22 2004 11:20 EDT
- in response to Vishal Revankar
How about this? Just took it from weblogic samples !
Let say the variables are: String strName, Boolean boolName, int intName
private int hashCode = -1;
public int hashCode(){
if (hashCode == -1) {
hashCode = strName.hashCode() ^ boolName.hashCode() ^ intName;
}
return hashCode;
}
Senthil. -
Composite Key in Entity Bean[ Go to top ]
- Posted by: Vishal Revankar
- Posted on: July 23 2004 01:00 EDT
- in response to Senthil Chinnaiyan
Hi Senthil,
Thanks for your immediate response. This approach looks fine(except the fact that I should wrap my boolean variable to Boolean object in order to get the hashcode out of it). But is there not a concrete step of doing this ? In most of the sample examples, I could see the varibles getting concatinated and then taken the hashcode out of it.
eg. (intName + strName + boolName).hashCode()
Is this also a right approach ? This returns a different hashcode if the sequence of the variables concatinated is changed.