The following question is from enthuware:
Identify the correct statements about the primary key of an entity:
a) It cannot consist of multiple fields.
b) It must be serializable and must also override equals and hashCode methods appropriately.
c) In an entity class hierarchy, the class for which the primary key has been defined must be the
root class of the hierarchy and must be an Entity class.
d) If property-based access is used, the properties of the primary key class must be public or protected.
e) The primary key class must be public or default accessed and must have a public no-arg constructor.
The correct answers are a) and d).
The explanation for b) being correct is: "The primary key class ..."
In my opinion b) isn't correct because the question asks for a "primary key" and not for a
primary key class or a composite primary key. So
@Id int id;
is a valid primary key and since id is of primitive type it hasn't even an equals or hashCode
method that could be overriden.