Multiple choice technology web technology

Which of the following must be satisfied by a component class?

  1. Implements java.io.Serializable

  2. Override equals() method

  3. Override hashCode() method

  4. Both a, b and c

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Hibernate component classes must implement java.io.Serializable to support caching and detach operations. They should override equals() and hashCode() to work correctly in collections and as map keys. All three requirements ensure proper behavior in Hibernate's persistence framework.

AI explanation

A distributable/serializable component class (such as an EJB or similar Java component) typically must implement java.io.Serializable so its state can be transmitted or persisted, and it must properly override equals() and hashCode() together so that object equality and hashing behave consistently (a well-known Java contract: if you override one, you must override the other). Satisfying only one or two of these would leave the class incorrectly comparable or unusable in hash-based collections.