Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

When using Primary Keys, why do I have to implement the hashCode() and equals() method in my bean?

0
Posted

When using Primary Keys, why do I have to implement the hashCode() and equals() method in my bean?

0

Implementing the hashCode() and equals() functions ensure that the primary key object works properly when used with hash tables. Hash tables are the preferred way EJB servers use to store and quickly retrieve instantiated entity beans. If session #1 uses widget “A” (which is an entity bean) then the server needs to do some work to instantiate and initialize the object. If session #2 then requests the same widget “A”, the EJB server will look in its hash table of existing entity beans of type widget to see if widget “A” has already been instantiated.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123