-->
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: Many-to-Many-to-Many
PostPosted: Mon Jan 10, 2005 11:28 am 
Newbie

Joined: Sat Jan 08, 2005 3:40 pm
Posts: 7
Location: New York
Let's say we have foo, bar, and fubar. A foo has many bars, a bar has many fubars. The reverse is also true. A fubar has many bars, a bar has many foos.

Our ERD consists of foo, bar, and fubar tables linked by two association tables to create the many-to-many associations.

foo -- foo_bar -- bar -- bar_fubar -- fubar

Given a foo, we want to know how many fubars we have. Given a fubar, we want to know how many foos we have.

How might one map this?

-S


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 12:01 pm 
Newbie

Joined: Sat Dec 24, 2005 10:04 pm
Posts: 4
i have the same problem. Does anyone know the solution for this?
thanks


Top
 Profile  
 
 Post subject: Many to Many relations
PostPosted: Tue Apr 25, 2006 3:07 pm 
Newbie

Joined: Wed Jan 18, 2006 4:17 pm
Posts: 8
One suggestion would be to modify you database design to have One-Many and Many-One relation. So could divide you Many-Many relation to one-many and Many-one by inserting a third table (say intersaction table )between two tables with many-many relation. So in your case u can inset one intersaction table called "fooIntbar" between foo and bar and thus foo-fooIntbar would be one to many relation and then fooIntbar-bar would be Many-one relation.

Thus you could get Many to Many relation for foo-bar. Same way for bar-fubar.

So lets say foo, bar and fubar are three tables,
then talking about the complex relation foo to bar is one to many, bar to fubar is Many to one (So fubar to bar is one to Many and bar is the Intersaction between foo and fubar)

For the mapping file of foo i would have this.....
<!-- Associations -->

<!-- bi-directional one-to-many association from foo to fooIntbar -->
<set name="barSet" lazy="true" inverse="true" cascade="all">
<key>
<column name="fooID"/>
</key>
<one-to-many class="bar"/>
</set>

For the mapping file of fubar i would have this......
<!-- Associations -->
<!-- bi-directional one-to-many association from fubar to bar -->
<set name="barFubarSet" lazy="true" inverse="true" cascade="all">
<key>
<column name="fubarID"/>
</key>
<one-to-many class="fubar"/>
</set>

For the mapping file of bar i would have this.......
<!-- Associations -->

<!-- bi-directional many-to-one association from bar to foo -->
<many-to-one name="fooObject" class="foo" not-null="true" cascade="all">
<column name="fooID"/>
</many-to-one>

<!-- bi-directional many-to-one association from bar to fubar -->
<many-to-one name="fubarObject" class="fubar" not-null="true">
<column name="fubarID"/>
</many-to-one>


Other then this Well I am not too sure how we could implement Many-Many relation. Let me know if you find this helpful and if it works for you then do not forget to give me credits......

Thanks.... goodluck...
crazee_dude


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 3:43 pm 
Newbie

Joined: Sat Dec 24, 2005 10:04 pm
Posts: 4
Thanks! This seems helpful. I shall let you know how it works out. I am not sure if i can give you credits - I think it has to be the original poster.
Cheers
Akshay


Top
 Profile  
 
 Post subject: Many to Many relations
PostPosted: Tue Apr 25, 2006 6:33 pm 
Newbie

Joined: Wed Jan 18, 2006 4:17 pm
Posts: 8
You could also use some tool like Middlegen to generate the mapping file. Its easy to use it and also quick to generate the hbm files instead of doing it manually. This way you could also avoid the errors that we make while manually writing the mapping files.

Middlegen is a free tool......


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.