表示一个继承层次结构的有4中方法
1.每个带有隐式多态的具体类一张表
2.每个子类一张表
3.每个带有联合一张表
4.每个类层次结构一张表
1.每个带有隐式多台的具体类一张表
1.对于父类的属性,子类全部都在自己表中放至相应的字段,即在表中加上父表的字段,父类无单独的一张表
2.父类上加入@mappedSupperClass,然后子类就会继承父类,而且子类也可以改写父类的字段属性
名.eg.
@AttributeOverride
(name =
"owner"
, column =
@Column
(name =
"CC_OWNER"
, nullable =
false
))
MappedSuperclass
annotation can be mapped in the same way as an entity except that the mappings will apply only to its subclasses since no table exists for the mapped superclass itself】,在数据库中,关联通常被表示为外键关系,如果子类全部映射到不同的表【标识符属性映射不能被共享】,对于基类的多态关联就无法表示为一个简单的外键关系,此中继承映射很少被使用
@MappedSuperclass
public
class
BillingDetails {
private
String
owner
;
public
String getOwner() {
return
owner
;
}
public
void
setOwner(String owner) {
this
.
owner
= owner;
}
}
子类:
@Entity
@Table
(name=
"billing"
)
@AttributeOverride
(name =
"owner"
, column =
@Column
(name =
"CC_OWNER"
, nullable =
false
))
@GenericGenerator
(name=
"native"
, strategy=
"increment"
)
public
class
CreditCard
extends
BillingDetails {
@Id
@GeneratedValue
(generator=
"native"
)
private
long
id
;
private
String
number
;
public
long
getId() {
return
id
;
}