http://docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance-tablepersubclassQuote:
9.1.4. Mixing table per class hierarchy with table per subclass
You can even mix the table per hierarchy and table per subclass strategies using the following approach:
<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">
<join table="CREDIT_PAYMENT">
<property name="creditCardType" column="CCTYPE"/>
...
</join>
</subclass>
<subclass name="CashPayment" discriminator-value="CASH">
...
</subclass>
<subclass name="ChequePayment" discriminator-value="CHEQUE">
...
</subclass>
</class>
For any of these mapping strategies, a polymorphic association to the root Payment class is mapped using <many-to-one>.
<many-to-one name="payment" column="PAYMENT_ID" class="Payment"/>
I have a subclass /join table setup using a discrimnator value. The join table as described needs a sub tag called key in section 9.1.3
http://docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance-tablepersubclassQuestions:
1. Has anyone tried setting up polymorphism using the many-to-one element in the sub-class? I understand the <join table...> tag requires to have a <key> as a sub element. What if the columns in<key
column..> in the sub class and <many-to-one
column..> are the same. How do you get around the duplicate column issue?
2. Do you have any other strategies to access root attributes from sub classes?