使用hibernate时,你是否遇到如下蛋疼大场景
@Entity
@Table(name = "contr_Contract")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@MetaData(value = "合同")
public class Contract extends BaseEntity<Long> {
@MetaData(value = "合同编号")
@EntityAutoCode
private String contrNo;
@MetaData(value = "合同类型")
@EntityAutoCode
private ContrTypeEnum contrType;
@MetaData(value = "销售合同")
private SaleContract saleContr;
@MetaData(value = "代理合同")
private ProxyContract proxyContr;
@MetaData(value = "租赁合同")
private LeaseContract leaseContr;
@MetaData(value = "赠予合同")
private GiftContract giftContr;
...............略.........................
}
来吧 使用 Hibernate @any
@Any( metaColumn = @Column( name = "contr_class_type" ), fetch=FetchType.EAGER ,optional=true)
@AnyMetaDef(
idType = "long",
metaType = "string",
metaValues = {
@MetaValue( value = "SALE", targetEntity = SaleContract.class),
@MetaValue( value = "PROXY", targetEntity = ProxyContract.class ),
@MetaValue( value = "LEASE", targetEntity = LeaseContract.class ),
@MetaValue( value = "GIFT", targetEntity = GiftContract.class ),
} )
@JoinColumn( name = "contr_id" )
@Index(name = "contr_id",columnNames={"contr_id"})
public ContractBaseEntity getContr() {
return contr;
}
@Any ->
metaColumn = @Column( name = "contr_class_type" ) 辨别类别 具体存的是
@AnyMetaDef 定义的 @MeteValue.value 值