I have a table we can call Parent_Child in a legacy system. This table connects parents and children. The primary key is ParentId and ChildId as a composite-id.
However, both parent and child are really the same object, Person. So I have a many-to-one relationship to Person for both these columns, i.e., two relationships to the same table.
I also have a relationship to another table, so I cannot change the table structure here, but am forced to live with it.
My question is: How do I connect Parent_Child to Person in the hbm.xml files? I can do something like this in ParentChild.hbm.xml:
<many-to-one
name="parent"
class="Person"
column="PARENTID"
insert="false"
update="false"
/>
<many-to-one
name="child"
class="Person"
column="CHILDID"
insert="false"
update="false"
/>
But how do I map this relationship in Person.hbm.xml?
I can do this:
<set
name="parentchildren"
inverse="true"
>
<key
column="PERSONID" />
<one-to-many
class="ParentChild"
/>
</set>
That's one column. How do I map the other one? What do I call the set? Or am I going about this the wrong way? :)
I'd really appreciate any input on this. Thanks.
Kristoffer
Edit: After looking through the manual once again I stumbled onto paragraph 8.4. Could this be what I want? But on the other hand it seems to be based on the fact that Person has a composite primary key, which it has not ...
Last edited by Kristoffer on Tue Apr 04, 2006 8:06 am, edited 1 time in total.
|