Hibernate继承映射注释具有来自不同表的继承类型SINGLE_TABLE和discriminator列

时间:2013-09-18 13:37:01

标签: java sql hibernate inheritance hibernate-mapping

我在数据库中有以下架构。

Table1 : 
     Purchase_Type
         purchase_type_id
         purchaseType

Table2 :
     Purchases
         purchase_id
         amount
         purchase_type_id

我想为Purchases实体使用hibernate的hibernate“Single table”继承,子类将基于Purchase_Type表中的“purchaseType”,该表由“purchase_type_id”外键从“Purchases”表引用。我怎样才能做到这一点?
是否可以在单个表中引用“SINGLE Table”继承策略中的discriminator列的列?

@Entity
@Table(name = "purchases")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="purchase_type", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue(value = "None")
public class Purchases {

}

@Entity
@DiscriminatorValue("xyz")
public class PurchaseType1 extends Purchases {
}

我希望在Purchases中注释@DiscriminatorColumn的“purchase_type”属性引用“Purchase_Type”表中的“purchaseType”。 @DiscriminatorValue中的属性引用“Purchase_Type”表中相应的“purchaseType”值。

0 个答案:

没有答案
相关问题