Hibernate version: 2.1.8
Name and version of the database you are using: HSQLDB 1.7.3.3
Hi, I know this question has been asked dozens of times here and elsewhere, but no direct answer seems to have been given and I've been searching for days. RTFM is certainly fair enough except that in this case there is no coverage of the issue in the manual (I have read section 6.10, but it doesn't help).
The issue is how to map a typical parent/child relationship, where the parent can be one of several
unrelated classes. Simple example:
Code:
public class ParentA {
String id;
Set children;
...
}
public class ParentB {
String id;
Set children;
}
public class Child {
String id;
Object parent;
...
}
This is what I
would have done, but it won't validate against the hibernate-mapping DTD, so it's obviously wrong.
Mapping documents: Code:
<hibernate-mapping>
<class name="ParentA" table="PARENTS_A">
<id name="id" column="id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
...
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="ParentB" table="PARENTS_B">
<id name="id" column="id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
...
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="Child" table="CHILDREN">
<id name="id" column="id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<many-to-any id-type="string">
<column name="parent_class"/>
<column name="parent_id"/>
</many-to-any>
...
</class>
</hibernate-mapping>
According to the DTD, this is not the way to use many-to-any, but I cannot find any examples (on the site, in the manual, in the forums, or in two different books) of how it is actually done. Does anyone have an example handy of how to solve this very common problem?