【发布时间】:2017-10-12 09:24:08
【问题描述】:
我读到了这个问题:Hibernate Annotation using base entity
它提到了将@MappedSuperclass 与@Id 一起使用。
@MappedSuperclass
class BaseEntity {
@Id
private int id;
//getters and setters.
}
@Entity
class Movie extends BaseEntity {
@Column
private String name;
@Column
private int year;
@Column
private int durationMins;
//getters and setters
}
但是,如果我有多个派生实体扩展 BaseEntity 并且派生实体表对基实体中定义的列具有不同的列名,该怎么办?例如:
@Entity
@Table(name = "A")
class A extends BaseEntity {
}
@Entity
@Table(name = "B")
class B extends BaseEntity {
}
而在表 A 中,id 列称为“A_id”,而在表 B 中,id 列称为“B_id”。如何配置 baseentity 中 id 列的映射,使其映射到派生实体中的不同列?
【问题讨论】:
标签: hibernate annotations