What are the requirements for an IdClass in EclipseLink?

419 views Asked by At

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?

1

There are 1 answers

2
Vlad K On BEST ANSWER

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.