使用JPA的@SecondaryTable来实现hibernate的混合使用“每个类分层结构一张表”和“每个子类一张表”的功能

 
@Entity
@Table(name 
=   " T_BASE " )
@Inheritance(strategy 
=  InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name 
=   " CATEGORY " , discriminatorType  =  DiscriminatorType.STRING)
public   class  BaseDomain  {
}


@Entity
@DiscriminatorValue(
" sub1 " )
public   class  SubDomain1  extends  BaseDomain  {
}


@Entity
@SecondaryTable(name 
=   " T_SUB2 " )
@DiscriminatorValue(
" sub2 " )
public   class  SubDomain2  extends  BaseDomain  {
    
private String ext;

    @Column(table 
= "T_SUB2", name = "EXT2")
    
public String getExt() {
        
return ext;
    }

    
public void setExt(String ext) {
        
this.ext = ext;
    }

}

你可能感兴趣的:(Hibernate,ext,jpa,table,Class,inheritance)