-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Self-association. How to?
PostPosted: Wed Sep 21, 2005 8:02 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
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.


Top
 Profile  
 
 Post subject: Re: Self-association. How to?
PostPosted: Wed Sep 21, 2005 9:21 am 
Newbie

Joined: Wed Jul 20, 2005 11:32 am
Posts: 7
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.