JPA 表继承和 object 映射
JPA tables inheritance and object mapping
是否可以用基 class 映射 baseTable 并告诉 JPA 工具不要在 class 中插入 baseTable 中的字段?
我在我的数据库的每个 table 中都有我想要的字段 creation-date,所以我用该字段创建了一个 baseTable,其他 table 扩展了这个 baseTable。
当我生成用于映射此结构的 classe 时,japtool 会为我创建每个 table 和 creation-date 字段,这显然我只想在 baseEntity class 而不是每个 child class。
有办法实现吗?
如果我没有正确理解你的回答,我认为你正在寻找 JPA Inheritance
@MappedSuperclass
public class BaseEntity {
@Id
protected Integer id;
protected Date createdDate;
...
}
@Entity
public class EntityA extends BaseEntity {
protected String otherAttribs;
...
}
@Entity
public class EntityB extends BaseEntity {
protected Float differentAttribs ;
...
}
是否可以用基 class 映射 baseTable 并告诉 JPA 工具不要在 class 中插入 baseTable 中的字段?
我在我的数据库的每个 table 中都有我想要的字段 creation-date,所以我用该字段创建了一个 baseTable,其他 table 扩展了这个 baseTable。
当我生成用于映射此结构的 classe 时,japtool 会为我创建每个 table 和 creation-date 字段,这显然我只想在 baseEntity class 而不是每个 child class。
有办法实现吗?
如果我没有正确理解你的回答,我认为你正在寻找 JPA Inheritance
@MappedSuperclass
public class BaseEntity {
@Id
protected Integer id;
protected Date createdDate;
...
}
@Entity
public class EntityA extends BaseEntity {
protected String otherAttribs;
...
}
@Entity
public class EntityB extends BaseEntity {
protected Float differentAttribs ;
...
}