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: Association mapping with 3 or more tables. [How to?]
PostPosted: Tue Oct 21, 2008 11:42 am 
Newbie

Joined: Tue Oct 21, 2008 11:21 am
Posts: 1
Most Hibernate examples are in terms of 2 tables.

However, we already have an existing (read legacy) database. Most of the associations are between atleast 3 tables. As a result the join table/association table consists of 3 FKs from each of the 3 tables, in addition to the association's properties. Moreover, the application is always interested in dealing with the AssocationTable entity and never the primary entities themselves.

Let me give you an example: We have 3 tables as follows:
1. Agency [PK:AgencyID]
2. Agency_Website (An agency can have multiple websites) [PK:SiteID]
3. ThirdPartyVendors (A list of all the 3rd party vendors that the agency can connect to) [PK:VendorID]

Now the 4th table is the Join table - AgencyWebsiteVendorConnection. Its columns are as follows:
1. AgencyID
2. SiteID
3. VendorID
4. ConnectionCredentialKey [can contain values like Username, Userid, accountNo - since different vendors have different names for identifying users]
5. ConnectionCredentialValue [actual values for the above key]

This is the simplest example we have. Most other examples have more than 4 tables and the join exists between 4 or more tables at a time. At that point of time, we tend to loose focus on the multiplicity of the association - we cannot distinguish whether the join table is 1-many, many-many etc.

Can someone please provide an example of how these mappings can be done?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2008 4:18 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think the recommendation is to map the association tables as full entities. If it is as you say that the application is mainly interested in managing the associations tables, this will make life a lot easier. The main problem may be that you need composite primary keys, but there are some good examples of that here: http://www.hibernate.org/hib_docs/v3/re ... iteid.html


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.