如何在多继承实体复合键案例中使用IdClass?
@IdClass(IdClassEntity1.class)
class Entity1 {
private long e1pk1;
private long e1pk2;
}
@IdClass(IdClassEntity2.class)
class Entity2 extends Entity1 {
private long e2pk1;
private long e2pk2;
}
class Entity3 extends Entity2 {
private long e3pk1;
private long e3pk2;
}
应该是IdClassEntity2:
class IdClassEntity2 {
private long e1pk1;
private long e1pk2;
private long e2pk1;
private long e2pk2;
}
或
class IdClassEntity2 {
private IdClassEntity1 idClassEntity1;
private long e2pk1;
private long e2pk2;
}
答案 0 :(得分:1)
您可以使用@MappedSuperClass
或@Entity
来声明@IdClass
。 pk通过继承传播。
例如,使用@MappedSuperClass
,您可以执行以下操作:
@MappedSuperClass
@IdClass(IdClassEntity1.class)
public class Entity1 {
@Id private long e1pk;
@Id private long e1pk;
...
@Entity
public class Entity2 extends Entity1 {
...
使用@Entity
,遵循相同的范例