好吧,如果你阅读Hibernate文档的“传承”一章远一点
:-)你会看到,表每层次和表每个子类策略混合给出的例子是在现实中没有超过表格,每带有辅助表的层次结构:
<class name="Payment" table="PAYMENT"> <id name="id" type="long" column="PAYMENT_ID"> <generator /> </id> <discriminator column="PAYMENT_TYPE" type="string"/> <property name="amount" column="AMOUNT"/> ... <subclass name="CreditCardPayment" discriminator-value="CREDIT"> <join table="CREDIT_PAYMENT"> <property name="creditCardType" column="CCTYPE"/> ... </join> </subclass> <subclass name="CashPayment" discriminator-value="CASH"> ... </subclass></class>
您可以使用
@SecondaryTableannotation:
@Entity@Inheritance(strategy=InheritanceType.SINGLE_TABLE)@DiscriminatorColumn(name="PAYMENT_TYPE")@DiscriminatorValue("PAYMENT")public class Payment { ... }@Entity@DiscriminatorValue("CREDIT")@SecondaryTable(name="CREDIT_PAYMENT", pkJoinColumns={ @PrimaryKeyJoinColumn(name="payment_id", referencedColumnName="id"))public class CreditCardPayment extends Payment { ... }@Entity@DiscriminatorValue("CASH")public class CashPayment extends Payment { ... }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)