moonlight wrote:
Hibernate version: 3.0
Hello everyone,
I have doubts about how should I make a self association. It goes as follows: I have a PERSON table. This person table will have two special fields: Father, mother. The content of this field will be taken out of the same table. What kind of association is that? I suppose it's a many to one... I tried like this:
<many-to-one name="father" column="father" class="auge.bean.Person"
not-null="false" lazy="false"/>
but just doesn't work.
How should I do it?
Thanks, see ya.
I am assuming that you are aiming for a one-to-many self association between Child-Parent roles. Here is a sample mapping that should work for you -
<class name="Prsn" table="Prsn">
..................
<set name="Person" inverse="true">
<one-to-many class="Prsn"/>
<key column=/>
</set>
<many-to-one column="Child_ID" name="child" class="Prsn"/>
</class>
A Many-to-Many is also possible. Let me know if this helps.
P.S. Don't forget to rate if the reply helps you.