Its actually spelled out (not the separate schema part, but that's easy) on the hibernate site which shouldn't be surprising since its an excellent site.
There are two tricks to making this work :
- Map the children into the parent as a many-to-many, but set "unique='true'" in the mapping.
- Map the join table into the child object.
In my case this meant something along the lines of this in the parent :
<set name="children" table="XREF" schema="PARENT_SCHEMA"
lazy="false" inverse="true">
<key column="XREF_PARENT_ID" not-null="true" />
<many-to-many unique="true" column="XREF_CHILD_ID" class="com.jeremyrdavis.Child" />
</set>
And this in the child :
<join table="PARENT_SCHEMA.XREF" inverse="true" optional="true" >
<key column="XREF_CHILD_ID" not-null="true" />
<many-to-one name="group" column="XREF_PARENT_ID" not-null="true"></many-to-one>
</join>
Blogged with the Flock Browser