-->
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: Example of many-to-many using two many-to-one associations?
PostPosted: Thu Dec 08, 2005 3:55 am 
Newbie

Joined: Sat Dec 03, 2005 3:03 am
Posts: 5
Can anyone point me to an example where a many-to-many relationship is mapped using two many-to-one relationships using an association entity (instead of a single many-to-many) with a composite key and an extra properties? I need to to be bidirectional. The DB looks like this:

_______
PARENT |
Id |
Name |
etc. |
_______'

______________
PARENT_CHILD |
ParentId (PK) |
ChildId (PK) |
Relationship |
-------------------'
_______
CHILD |
Id |
Name |
etc. |
---------'


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 4:53 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
We do this all over the place. A classic example is associating "person" with "company" -- it's many-to-many, and you need to keep a description of the relationship in the association table.

The only thing we do differently is is that the association table also has a single-column surrogate primary key. Its references to the "parent" and "child" tables are foreign keys only.

If possible I would change your association table to work that way, it will work much better with NHibernate. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 5:58 pm 
Newbie

Joined: Sat Dec 03, 2005 3:03 am
Posts: 5
So how do you enforce at the db level that the same person is not related to the same company multiple times? Do you manually apply a unique index to the columns?


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.