Hi,
Is it possible to do this when the parent-child relationship involved joined-subclasses?
We have a similar situation in that the parent-child relationship is defined in a single table for a superclass Entity:
ID PARENT_ID NAME
-------------------------------------
1 0 parent
2 1 child one
3 1 child two
However, we have two tables for classes that extend the base class, Thing and ChildThing, something like this:
ID EXTP_FIELD1 EXTP_FIELD2
------------------------------------------------
1 extended parent ext parent desc.
ID EXTC_FIELD1 EXTC_FIELD2
-------------------------------------------------------
2 extended child one ext child one desc.
3 extended child two ext child two desc.
The subclasses are such that the Thing has a Set of ChildThing objects. But these are known by the PARENT_ID column in the Entity table, not from any field in the Thing or ChildThing table. When I try to set up a
one-to-many relationship in the Thing mapping using PARENT_ID as the key, Hibernate attempts to get PARENT_ID from the ChildThing table instead of the Entity table where it actually lives.
This is the mapping for the Thing class:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<joined-subclass name="ext.Thing" extends="base.Entity" table="THING">
<key column="ID"/>
<property name="extpField1" column="EXTP_FIELD1"/>
<property name="extpField2" column="EXTP_FIELD2"/>
<set name="childthings" lazy="false" table="CHILDTHING">
<key column="PARENT_ID" not-null="true"/>
<one-to-many class="ext.ChildThing"/>
</set>
</joined-subclass>
</hibernate-mapping>
and for the Entity class:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="base.Entity" table="ENTITY">
<id name="id" column="ID" type="string"/>
<property name="parentId" type="string" not-null="true" column="PARENT_ID"/>
<property name="name" type="string" not-null="true" column="NAME" />
</class>
</hibernate-mapping>
The mapping file for ChildThing looks nearly identical to the Thing mapping file.
Any idea how I can get Hibernate to take the one-to-many parent key from the Entity table and not the ChildThing table?