I'm having a major problem getting a parent/child relationship working for a hierarchy of a single class. Basically I have to represent a server tree like thus:
Server A
Server B
Server C
Server D
Server E
Server C
Server D
Server F
Server G
Note that the children of Servers B & E are the same. My original mapping was something like this, which was fine until I needed to have the objects for server C & D being the same instance, so having a single column for PARENT_ID got filled by the last relationship and only one of servers B or E would show the children:
<hibernate-mapping ...>
<class name="Server" ...>
...
<set name="children" cascade="all-delete-orphan" lazy="false">
<key column="PARENT_ID" />
<one-to-many class="Server" />
</set>
</class>
</hibernate-mapping>
I know I need to do some sort of cross reference table to map the fact that a server can have multiple parents, but all the examples I've found on-line contain a separate parent and child class.
Can anyone tell me how to do a cross reference parent/child mapping for the same class...? I.e. something like:
<hibernate-mapping ...>
<class name="Server" ...>
...
<set name="children" cascade="all-delete-orphan" lazy="false">
<key>
<column name="PARENT_ID" />
<column name="CHILD_ID" />
</key>
<many-to-many class="Server">
<column name="???" />
<formula>???</formula>
</many-to-many>
</set>
</class>
</hibernate-mapping>
Thanks,
Bob.