欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

inheritance mapping

程序员文章站 2022-07-15 13:12:58
...
the three strategies:
[list]
[*]table per class hierarchy
[*]table per subclass
[*]table per concrete class
[/list]

[b]1.Table per class hierarchy[/b]
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 [i]not null [/i]constraints.