有没有办法在 Hibernate 中创建带有注释的复合键,而无需创建新的 PK 类(即@EmbeddedId)?
我的问题是,我有一个具有许多属性的抽象类 CommonClass,我需要为许多实体类继承它。每个类都有不同类型的 id,但它们都需要是具有 CommonClass 属性的复合键。例子:
@MappedSuperclass
abstract class CommonClass {
@Id
int typed;
int a0;
int a1;
//many other attributes
}
@Entity
class EntityString extends CommonClass {
@Id
String id;
//ID need to be id+typed from CommonClass
//other attributes
}
@Entity
class EntityInteger extends CommonClass {
@Id
Integer id;
//ID need to be id+typed from CommonClass
//other attributes
}
那么,最好的方法是什么?