Hi I am using a single table to match the inheritance of the class hierarchy for legacy data, as described here.
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tableperclass
this is what my display looks like
<class abstract="true" name="note" table="NOTES">
<id name="id" type="long" column="NOTE_ID">
<generator class="native"/>
</id>
<discriminator column="NOTE_TYPE" type="string"/>
<property name="orderId" column="ORDER_ID"/>
<property name="text" column="TEXT"/>
<subclass name="PurchaseNote" discriminator-value="PUR" />
<subclass name="CancelNote" discriminator-value="CAN" />
<subclass name="RefundNote" discriminator-value="REF" />
</class>
For each order ID
there may be many subclasses of notesNotes are described as associations in the order class, for example
<class name="order" table="ORDERS">
<id name="id" type="long" column="ORDER_ID">
<generator class="native"/>
</id>
.....
<set name="purchaseNotes">
<key column="orderId" />
<one-to-many class="PurchaseNote"/>
</set>
<set name="cancelNotes">
<key column="orderId" />
<one-to-many class="cancelNote"/>
</set>
<set name="refundNotes">
<key column="orderId" />
<one-to-many class="refundNote"/>
</set>
</class>
I can get related collections obtained using hibernate if I do the following.
1) Use the Where clause in the set definition in xml order or 2) Use force = "true" as part of the discriminator definition in xml notes
, DAO hibernate factory, HQL
"from RefundNote, orderId =?"
"from Note note note.class= RefundNote orderId =?" RefundNote Order, setter on refundNotes.
?
, 3 ( ) . ....?
, , ( , , ..) singe db - .....?
Java .simpleName, , -, .....?