-->
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.  [ 6 posts ] 
Author Message
 Post subject: recursive parent child relationship in hbm.xml mapping file
PostPosted: Sun Feb 04, 2007 12:17 pm 
Newbie

Joined: Sun Feb 04, 2007 11:58 am
Posts: 6
I a have a Partiton Table who could have 0 to n Child as Partiton...so i must have a recursive relation where a Partiton could have zero to many Partiton Child.

I never mapped with ORM such a relation and since i work with Hibernate this is the first project where i have such parent child relation in a recursive way.
since i found nothing about such situation i do not even know if hibernate support recursive relationship (i hope it support..because this is a very common relationship in application DB)

could some body help me with the way that i have to write the recursive relation in my mapping hbm.xml file


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 6:33 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Does a partition have at most one parent partition? If it does, just add a ParentPartitionID column to your Partition table, and map it like any other one-to-many collection. If it doesn't, create a ParentToChildLink table (ParentPartitionID, ChildPartitionID), and map it as a normal many-to-many collection. So long as you use the right columns in your mapping, hibernate handles this fine.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: recursive call and my requirement
PostPosted: Sun Feb 04, 2007 10:16 pm 
Newbie

Joined: Sun Feb 04, 2007 11:58 am
Posts: 6
Ok from what i have as requirement here is the scope

My Partition could have as Parent either another Partition, or SystemRelease Table or nobody.

There is a bidirectional many to many relationship between SystemRelease and Partition and then There is the recusrive relationship on Partiton model.

The many to many relationship between SystemRelease and Partition is (0..1) to n
And the recusrive relationship beween Patitions is
(0..1) to n.

As it is specified in the requirement i could have a Partition that do not belong to neither another Partiton or any SystemRelease.

My SystemRelease is made of Patition...But a Partition could belong to no body...and do not have a Parent.

From this perspective i could have a Parent for Partition or Not having a Parent.

So even the fact that a Partition could have as a Parent another table (SystemRelease) or another Partition or nobody could have impact on the solution that you Propose me (creating a ParentToChildLink table (ParentPartitionID, ChildPartitionID), and map it as a normal many-to-many collection) ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 10:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Why is the SystemRelease to Partition relationship many-to-many? You said it's (0..1) to n: that's one-to-many. Can one Partition be in more than one SystemRelease?

Anyway, the relationships are unrelated. If you need a many-to-many relationship between SystemRelease and Partition, then you need a separate link table between them. It does not affect the Partition-Partition relationship.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 2:43 am 
Newbie

Joined: Sun Feb 04, 2007 11:58 am
Posts: 6
well i made mistake...i guess i'm just to tiered working extra hours in weekend for Motorola..

The relationship between SystemRelease and Partition is one to many and not many to many...your remark it well.

Here is the way i code the recursive relationship in Partition regarding your suggestion :

<set name="childPartitions" table="PARTITION_PARTITION" cascade="save-update">

<key column="PARENT_PARTITION_ID"/>

<!-- Notice that by specifying unique="true", we have changed the multiplicity from many-to-many to one-to-many -->

<many-to-many column="CHILD_PARTITION_ID" unique="true" class="com.motorola.gwt.cair.client.model.Partition"/>
</set>

and in here is the relation in SystemRelease:

<set name="childPartitions" table="SYSTEM_RELEASE_PARTITION" cascade="save-update">
<key column="SYSTEM_RELEASE_ID"/>
<!-- Notice that by specifying unique="true", we have changed the multiplicity from many-to-many to one-to-many -->
<many-to-many column="PARTITION_ID" unique="true" class="com.motorola.gwt.cair.client.model.Partition"/>
</set>

Friend, is it OK like this ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 4:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That looks like a good mapping to me. If a Partition can be in only one SystemRelease, then you may choose to drop the SYSTEM_RELEASE_PARTITION table and put a SystemReleaseID column in the partition table, but your solution is just as valid. And it'll work without change if the relationship ever changes to many-to-many.

_________________
Code tags are your friend. Know them and use them.


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