-->
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.  [ 3 posts ] 
Author Message
 Post subject: Parent/Child mapping
PostPosted: Tue Oct 17, 2006 6:33 pm 
Newbie

Joined: Wed Sep 20, 2006 10:15 pm
Posts: 12
Hi folks,

I have a simple table called Dog which has:

ID
Name
Dam
Sire

where Dam and Sire are self-referencing foreign keys to the Dog.ID column.

I have mapped everything to that table successfully except for the uni-directional parent/child mapping. I have mapped the dam and sire properties successfully. It's the "progenies" colletion that's somewhat problematic.

Currently I have:

<set name="progenies" inverse="true">
<key column="dam"/>
<one-to-many class="Dog"/>
</set>

which works just fine, except it's only referenced through the dam foreign key. I can't add another <key> in there either.

Any suggestions of how I can handle this? Do I have to do two collections of progeniesByDam, and progeniesBySire?

TIA,
Dany.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 6:49 pm 
Newbie

Joined: Tue Jul 04, 2006 3:42 am
Posts: 9
Hi,

I guess that you have to. I mean you have to create two tables. That was how i solved the prblem, which seems to be logical for me. In the case where only the reference to the owning table is specified, there is no other way. But if there is a way to insert an extra column to the table which specifies from which (java) list the referencing table comes from , then the things change. That would be wonderful to learn it.

Siyamed


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 7:03 pm 
Newbie

Joined: Wed Sep 20, 2006 10:15 pm
Posts: 12
siyamed wrote:
I guess that you have to. I mean you have to create two tables. That was how i solved the prblem, which seems to be logical for me. In the case where only the reference to the owning table is specified, there is no other way. But if there is a way to insert an extra column to the table which specifies from which (java) list the referencing table comes from , then the things change. That would be wonderful to learn it.


Thanks Simayed, I'm not entirely sure what you mean by "create two tables" though. Do you mean database tables? For ancestral relationship of the same entity type I can't imagine having two tables. A human's parents will always be humans, a dog's dam and sire will always be dogs (broad traditional assumptions here...).

In the end I have solved it with some slightly dubious method. The table has a Gender column so I basically map the two sets of progenies, ie. progeniesBySire, and progeniesByDam. These two properties and their getters/setters are private, only to be used by Hibernate.

I then have a third property, called "progenies". The getter checks what gender the Dog is and returns the appropriate set!

It all sounds very dodgy to me but it works so far...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.