对于Hibernate提供的4种兼容JPA的映射策略,这里介绍第四种table-per-concrete-class策略。事实上,从数据库表结构看,这种策略下的每个Entity类都对应一个独立的数据库表。
在这种策略中,存在如下特征:
- 父子Entity类也对应一个数据库表
- 父表中无需设置discriminator列
- 子表中不仅包含子Entity类特有的全部属性,还包括从父Entity类继承的属性
父Entity类定义如下:
@Entity(name = "Account")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public static class Account {
@Id
private Long id;
private String owner;
private BigDecimal balance;
private BigDecimal interestRate;
public Long getId() {