I am using eclipselink
for JPA
. I have an entity, which has a composite key fabricated out of two fields. Following is my Embeddable primary key class' fields(members).
@Embeddable
public class LeavePK {
@ManyToOne(optional = false)
@JoinColumn(name = "staffId", nullable = false)
private Staff staff;
@Temporal(TemporalType.TIMESTAMP)
private Calendar date;
//setters and getters
}
My entity is going to hold leave data related to a staff, so I am trying to combine staff object and leave date to produce composite key. Apart from my logic, it is not allowing me to have a foreign key mapping inside embeddable class. When I try to use JPA tools--> Generate Tables From Entity, it gives error as below, which explains, but I am not getting it.
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The mapping [staff] from the embedded ID class [class rs.stapp.entity.LeavePK] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [leavePK] from the source [class rs.stapp.entity.Leave]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded.
Does it mean, I cannot have a key(from composite key) which is also a foreign key. Is there a alternative way to accomplish this ERM? Please help. Thanks