Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primary Key Class

 
Rajib Sarma
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Why do we need to override the methods equals() and hashCode() for a primary key class?
Thanks
-Rajib
 
Snigdha Solanki
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primary Key Class need to override hashCode() so that it can be stored in a Hashtable. Container internally stores all the entity beans it has in memory in a hashtable or some similar structure.
Similarly,primary key class need to override equals method as container calls this method to compare two primary keys so as to determine if two cached entity beans represent the same data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic