Reputation: 86627
I want to create a primary composite key
and use an @Id
field from a parent class. But it does not work. Why?
@MappedSuperclass
static abstract class SuperEntity {
@Id
private Long id;
}
@Entity
@IdClass(SuperPK.class)
public static class ChildEntity extends SuperEntity {
@Id
private String lang;
}
public class SuperPK {
public SuperPK(Long id, String lang) {
//...
}
}
Result: Property of @IdClass not found in entity ChildEntity: id
Upvotes: 1
Views: 1744
Reputation: 440
I found an open issue regarding this bug.
One of the comments states to override the getters for the ID properties as a workaround.
@Entity
@IdClass(SuperPK.class)
public static class ChildEntity extends SuperEntity {
@Id
private String lang;
@Override @Id
public Long getId() {
return super.getId();
}
}
Upvotes: 1