A developer is creating an entity which is mapped to a table that has a primary key constraint defined on two character columns and would like to use mapping defaults as much as possible to simplify the code.
Which two mapping options can be chosen? (Choose two.)
Correct Answer: C,E
Explanation/Reference:
C: Annotation Type EmbeddedId
Applied to a persistent field or property of an entity class or mapped superclass to denote a composite primary key that is an embeddable class. The embeddable class must be annotated as Embeddable.
E: Annotation Type IdClass
Specifies a composite primary key class that is mapped to multiple fields or properties of the entity. The names of the fields or properties in the primary key class and the primary key fields or properties of the entity must correspond and their types must be the same.
Example:
@ IdClass(com.acme.EmployeePK.class)
@ Entity
public class Employee {
@ Id String empName;
@ Id Date birthDay;
...
}
Reference: javax.persistence, Annotation Type EmbeddedId
javax.persistence , Annotation Type IdClass