Reputation: 1244
The EclipseLink user guide states that when constructing an IdClass (not embedded) for a composite primary key, it must have a public no-argument constructor and implement the methods equals
and hashCode
. In addition, the example it gives also implements getters and setters.
The Persistence WikiBook has a public constructor with arguments, no no-argument constructor, no getters and setters, and explicitly states that EclipseLink does not require implementation of equals
and hashCode
.
Which of these is really required? Can I use a minimal IdClass with just the attributes and no constructors and no methods, because EclipseLink will generate these for me? Is this dependent on the version of EclipseLink?
Upvotes: 2
Views: 454
Reputation: 421
Only no-arg constructor is required (which is generated by java unless you have another one defined). You can use a minimal class with attributes only.
However, EclipseLink wont generate anything in this case (even with weaving), which means that you may encounter unexpected problems with hash or equals based operations.
Upvotes: 3