I'm looking at the documentation for mapping implementations of an interface with joined-subclass (for the subclass-per-table stategy).
Code:
<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
<property name="amount" column="AMOUNT"/>
...
<joined-subclass name="CreditCardPayment" table="CREDIT_PAYMENT">
<key column="PAYMENT_ID"/>
...
</subclass>
<joined-subclass name="CashPayment" table="CASH_PAYMENT">
<key column="PAYMENT_ID"/>
...
</subclass>
<joined-subclass name="ChequePayment" table="CHEQUE_PAYMENT">
<key column="PAYMENT_ID"/>
...
</subclass>
</class>
Further down:
Quote:
For either of these two mapping strategies, a polymorphic association to Payment is mapped using <many-to-one>.
Code:
<many-to-one name="payment"
column="PAYMENT"
class="Payment"/>
So my understanding is that I add this mapping to every joined-subclass implementing class in the mapping document and I then add a getPayment() method to every Implementing class (of the Interface) so it can reference the Interface class?
I've tried this and everything executes OK but the column that I refer to in the many-to-one property 'column' is NULL every time I add an object of the Interface type.
My Interface type is also a member of a Collection of another object (on the many-valued end of a one-to-many relationship) but that should not really be an issue right?
I've read through all I can find on the forum about this but I'm still confused.
Damn! I really need that Hibernate in Action book :)
I use 2.1.1.
This is the mapping file if that helps:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.lehman.mis.model.CommissionProfile" table="COMMISSION_PROFILE">
<id name="id" type="integer" column="ID">
<generator class="identity"/>
</id>
<!-- A bi-drectional mapping. A CommissionProfile can't live without a Commission. -->
<many-to-one name="parent" class="com.lehman.mis.model.Commission" column="PARENT_ID" not-null="true"/>
<joined-subclass name="com.lehman.mis.model.RbCommissionProfile" table="RB_COMMISSION_PROFILE">
<key column = "ID"/>
<many-to-one name="commissionProfile" class="com.lehman.mis.model.CommissionProfile" column="COMMISSION_PROFILE"/>
<property name="timeStamp" type="timestamp">
<column name="TIMESTAMP" not-null="true"/>
</property>
<property name="comment" type="string">
<column name="COMMENT"/>
</property>
lots of properties follow....
</joined-subclass>
</class>
</hibernate-mapping>
I'll post the classes also if needed...