of this approach is that if a property
is mapped on the superclass
, the column name must be the same on all subclass tables. The identity generator strategy is not allowed in union subclass inheritance. The primary key seed has to be shared
across all unioned subclasses of a hierarchy.
Three tables are involved for the subclasses. Each table defines columns for all properties of the class, including inherited properties.
If your superclass is abstract, map it with abstract="true". If it is not abstract, an additional table (it defaults to PAYMENT in the example above), is needed to hold instances of the superclass.
There are two ways we can map the table per concrete class strategy.
First, you can use <union-subclass>.
<id name="id" type="long" column="PAYMENT_ID">
<property name="amount" column="AMOUNT"/>
<union-subclass name="CreditCardPayment" table="CREDIT_PAYMENT">
<property name="creditCardType" column="CCTYPE"/>
<union-subclass name="CashPayment" table="CASH_PAYMENT">
<union-subclass name="ChequePayment" table="CHEQUE_PAYMENT">