How u map a composite Primary Key in CMP Entity Bean and how u handle the same composite primary key in primary key class? What is the usage of HashCode() and Equals() methods? They return only one single primary key value?

Alessandro A. Garbagnati

I think you are making some confusion on the purpose of the equals() and hashCode(): they do not return a "single primary key value".

equals() returns a boolean that indicates whether another object is "equal" to this one, while
hashCode() returns an int that represent the hashcode of an object, that is used for the benefit of hashtables, like java.util.Hashtable.

anand narang also added that the reason why we have 2 methods is that hashcode may not always return unique values. So the container also calls the equals method to verify the uniqueness.

Check out the javadoc for those two methods
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.