-->
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: Many-to-many with extra field in the join table
PostPosted: Fri Apr 28, 2006 7:38 am 
Newbie

Joined: Tue Mar 07, 2006 3:15 pm
Posts: 17
Hi

I have a many-to-many (bidirectional) relationship working. I now want to add an extra field to the join table and let one of the sides populate with this field. Is this possible?

For example

A (mapped to table A) has a collection of Bs. B (mapped to table B) has a collection of As. Can each A instance here fetch a field from the join table (A_B) and set this in a property in the A object?

I know I can map the join table to an object and make two seperate 1:N relationships and thereby access the field, but I do not want an entirely new object, mappin etc for just one extra field.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 9:37 am 
Beginner
Beginner

Joined: Fri Apr 28, 2006 3:04 am
Posts: 22
Location: Amsterdam
It is not possible to populate one of the tables you mention with the extra property.
What you want to create a class for the join table with the extra property. This class needs a composite key with foreign key references.

Read this blog how to make it happen:

http://java-aap.blogspot.com/2006/04/hibernate-annoations-composite-primary.html#links


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 9:42 am 
Newbie

Joined: Tue Mar 07, 2006 3:15 pm
Posts: 17
Thanks.

By the way I really want to create the extra object as this helps preserve the many-to-many relationship. Populating one side with the value will give me a 1:N on that value and not a N:M..


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.