I am using the table-per-class-hierarchy mapping strategy to persist an entire class hierarchy into a singe table. I understand I can map a single subclass in this hierarchy to a separate table using the <join> mapping element. Is there a way, however, to persist an entire branch or subtree of this class hierarchy rooted at a given subclass to a seperate table?
Consider this simple example. Suppose we have four classes:
D extends C extends B extends A
I want to map A and B to one table and C and D to another table, with the latter having a foreign key into the former, using something like:
<hibernate-mapping>
<class name="A" table="rootTable" discriminator-value="A">
...
<subclass name="B" discriminator-value="B">
...
<subclass name="C" discriminator-value="C">
<join table="childTable">
...
<subclass name="D" discriminator-value="D">
...
</subclass>
</join>
</subclass>
<subclass>
</class>
</hibernate-mapping>
But the DTD for hibernate.hbm.xml does not allow nesting <subclass> elements under a <join> element! I can get around this problem by moving the <subclass> element for D ouside the enclosing <join> and adding the appropriate "extends" attribute, but that causes D to be persisted in the rootTable, not the childTable.
Is there another way to achieve what I want?
Any help/pointers/suggestions will be be greatly appreciated.
I am using Hibernate 3.2.
Thanks in advance.
-- Hira.
|