-->
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.  [ 2 posts ] 
Author Message
 Post subject: Updating other attributes in the intersection table
PostPosted: Tue Nov 18, 2008 5:15 pm 
Newbie

Joined: Thu Nov 13, 2008 11:37 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Hi I have successfully implemented many-to-many relationship using the collections object, and it is working fine. Now I have the following question.

How can I write other attributes in the intersection table while the inter relationship is being built?

For example my collection object is successfully putting the contacts_id and custodian_id in the intersection table BUT I also have to write id and custodian_type in the intersection table. How can I achieve that?

Any lead or help will be greatly appreciated. Thank you. If you need me to post the code and xml's I will do so.

Database tables:

Table: Contacts:
Columns:
id, first_name, last_name

Table: Custodian:
Columns:
id, custodian_name

Table: Contact_Custodian
Columns:
id, contact_id, custodian_id, custodian_type


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 8:55 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
This question is very common.
As soon as you start putting extra information in the relationship table, even just a couple of extra files, it is not a relationship table anymore, but another entity.

You should decompose your many-to-many relationship into one one-to-may relationship between contacts and contacts_custodians, and another many-to-one relationship between contacts_custodians and custodians.

Very few real-life applications manage to keep "pure" many-to-many relationships, and end up doing something like this.

_________________
Gonzalo Díaz


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