-->
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.  [ 6 posts ] 
Author Message
 Post subject: Ternary relationship and extra attribute question
PostPosted: Thu May 13, 2004 4:00 pm 
Newbie

Joined: Fri Mar 05, 2004 10:41 am
Posts: 12
I have 4 tables A, B, C, and D. D contains PK's of A, B, and C, and other extra fields. D does not have its own PK.

I know how to map my POJO's (AClass, BClass, CClass, and BCClass) using the composite-element approach:

<bag name="bcCollection" table="d" >
<key column="a_id" />
<composite-element class="BCClass" >
<many-to-one name="bClass" class="BClass" column="b_id" />
<many-to-one name="cClass" class="CClass" column="c_id" />
<property name="extraAttr" column="extra_field"/>
</bag>

Now, what will my mapping file look like if I use the Map and index-many-to-many approach?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 4:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can't with a tenary relation.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 4:09 pm 
Newbie

Joined: Fri Mar 05, 2004 10:41 am
Posts: 12
michael wrote:
You can't with a tenary relation.


So to confirm, my only choice is to use composite-element?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
micheal,
is the doc partially wrong?

Ternary Associations
There are two possible approaches to mapping a ternary association. One approach is to use composite elements (discussed below). Another is to use a Map with an association as its index:

<map name="contracts" lazy="true">
<key column="employer_id"/>
<index-many-to-many column="employee_id" class="Employee"/>
<one-to-many column="contract_id" class="Contract"/>
</map>
<map name="connections" lazy="true">
<key column="node1_id"/>
<index-many-to-many column="node2_id" class="Node"/>
<many-to-many column="connection_id" class="Connection"/>
</map>


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 7:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes you can of course do it that way. What you then can't do anymore though is to store additional information in the association table, unless I am really confused :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 9:01 pm 
Newbie

Joined: Fri Mar 05, 2004 10:41 am
Posts: 12
Thanks. A followup question:

In the above ternary relationship, my AClass contains a bag of BCClass. However, I always need to view and manipulate a Collection of CClass given an A and a B. So my object model should really be ABClass containing a bag of CClass. However, I have not figured out how this can be done. My understanding is that a top-level (entity) class needs to have an id/PK, but the BCClass does not have an id.

Any help is greatly appreciated!


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