inheritance mapping

the three strategies:
  • table per class hierarchy
  • table per subclass
  • table per concrete class


1.Table per class hierarchy
Suppose we have an interface Payment with the implementors CreditCardPayment and CashPayment. The table per class hierarchy mapping would display in the following way:
<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
<discriminator column="PAYMENT_TYPE" type="string"/>
<property name="amount" column="AMOUNT"/>
...
<subclass name="CreditCardPayment" discriminator-value="CREDIT">
<property name="creditCardType" column="CCTYPE"/>
...
</subclass>
<subclass name="CashPayment" discriminator-value="CASH">
...
</subclass>
</class>

Exactly one table is required. There is one limitation of this mapping:columns declared by the subclass cannot have not null constraints.

你可能感兴趣的:(inheritance)