-->
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.  [ 7 posts ] 
Author Message
 Post subject: many-to-many mapping
PostPosted: Thu Jan 29, 2004 7:35 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Hi,

I have a class A and B with many-to-many relationship.

The associate class is A_B.

However, my associate class contains some properties. In this case

how do I specify the many-to-many relationship in hbm.xml.


Do I have to break them up as two many to one relationship and create the A_B class.

Thanks
Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 7:52 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
such an association A<*---*>B is usually broken into

an association like this:
A--*>AB<*--B

this results in two <one-to-many> mapping xmls.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 8:40 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Thanks Ravi. What I wanted to know was that is there any way in hibernate where I can mention properties for many-to-many tag in the hbm.xml for class A or class B rather than having to have a separate class definition for AB and then doing a one-to-many from A to AB and one-to-may from B to AB.

Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 8:44 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can use a collection of composites. This is quite complex, but you need at least the association class. It is then mapped as a <composite-element>.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 8:54 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
So, breaking up the relation into two "one-to-many" and defining the associate class would be the way to go (best practices) from the point of view of complexity of using the many-to-many (only if the associate class has properties) ?

Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 8:59 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you are new to Hibernate, yes.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 9:09 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Thanks for the input. Guess I shall stick to the easier path and leave the fancier stuff for sometime later :).

Cheers!!


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