[英]JPA Inheritence IdClass
How to use IdClass in multiple inheritance entity composite key case ? 如何在多重继承实体复合键的情况下使用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;
}
what should be IdClassEntity2 : 什么是IdClassEntity2:
class IdClassEntity2 {
private long e1pk1;
private long e1pk2;
private long e2pk1;
private long e2pk2;
}
or 要么
class IdClassEntity2 {
private IdClassEntity1 idClassEntity1;
private long e2pk1;
private long e2pk2;
}
You can use a @MappedSuperClass
or @Entity
to declare the @IdClass
. 您可以使用
@MappedSuperClass
或@Entity
声明@IdClass
。 The pk is propagated via inheritance. pk通过继承传播。
For example, using @MappedSuperClass
, you can do the following: 例如,使用
@MappedSuperClass
,您可以执行以下操作:
@MappedSuperClass
@IdClass(IdClassEntity1.class)
public class Entity1 {
@Id private long e1pk;
@Id private long e1pk;
...
@Entity
public class Entity2 extends Entity1 {
...
Using @Entity
, follow the same paradigm 使用
@Entity
,遵循相同的范例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.