-->
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.  [ 5 posts ] 
Author Message
 Post subject: mappings with Parent - Child Tables
PostPosted: Tue Apr 04, 2006 8:32 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
I have two table ABC, CBZ
ABC contains ID as primary key
CBZ contains ParentId and ChildID as composite key

relation between ABC and CBZ is many to many, i have confusion with relationship amongs the mappings, i have given mapping for the two tables as below.

Mapping for Parent Table
<Class name="NodeBase">
<subclass name="MyAssembly.Node, MyAssembly" discriminator-value="0" >
<bag name="Nodes" table="ABC">
<key column="ParentID" />
<many-to-many class="MYAssembly.NodeRelation, MyAssembly" unique="true" />
</bag>
</subclass>
</Class>

Mapping for Child Table
<class name="MyAsembly.NodeRelation, MyAssembly" table="CBZ" >

<property name="GroupName" column="GroupName" type="string" not-null="true" />
<property name="ProjectName" column="ProjectName" type="string" not-null="true" />
<one-to-one name="Node" column="ChildID" class="MyAssembly.NodeBase, MyAssembly" not-null="true" />
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 11:08 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
I'm very new at hibernate, but if you have a many-to-many relationship I think you must have three tables, one to ABC, other to CBZ and another auxiliar table which shows the relation between them.

Read the code in hibernate's doc page 206 (pdf version) for see this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 11:16 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
please forgive me, I think I was in Hibernate forum, not in Nhibernate! So, you can't find the code in que page I said to you, but I still think the issue is the same: you will need three tables in the database to model a many to many relationship.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 1:27 pm 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
no main i dont want role of third table


Top
 Profile  
 
 Post subject: This is not Many-to-many
PostPosted: Tue Apr 04, 2006 5:20 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
What you have described above is a one-to-many relationship. The cbz table only has data to relate to a single parentId. So the Parent (ABC) has many children (CBZ) and the child has one parent. You will also have to read up on composite key mappings in the docs.


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