-->
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.  [ 1 post ] 
Author Message
 Post subject: How to use many-to-many relationship ID as foreign key
PostPosted: Thu Mar 12, 2009 3:54 pm 
Newbie

Joined: Thu Feb 26, 2009 7:30 pm
Posts: 7
I have table A and table B that are mapped to classes A and B respectively (you can assume the most simplistic mappings for now) that have identifiers A_ID and B_ID. They have a many-many relationship that is given an ID, AB_ID in an AB_Relationship table..

There is a third class C that is mapped to class C with identifier C_ID. C has a many-many relationship with A kept in the CA_Relationship table with ID CA_ID. I want to be able to pick what B's I can attach to this relationship by using the AB_Relationship table, but not necessarily all B's for the A related to C. So now I have introduced yet another relationship CA to B (Where the only B's available are those with an A-B relationship). I don't know where to begin on this last part.

Hibernate version:
3.2.4

Mapping documents:
A mapping
...
<class name="A" table="A">
<id name="A_ID" column="A_ID">
<generator class="sequence"/>
</id>
<idbag name="myBs" table="AB_Rltn" cascade="save-update">
<collection-id type="java.lang.Integer" column="AB_ID">
<generator class="sequence"/>
</collection-id>
<key column="A_ID" not-null="true"/>
<many-to-many column="B_ID" class="B"/>
</idbag>
</class>
...

B mapping
...
<class name="B" table="B">
<id name="B_ID" column="B_ID">
<generator class="sequence"/>
</id>
</class>

C mapping with relationship to A, but do not know how to put the CA to B relationship or if it would even go in this file
...
<class name="C" table="C">
<id name="C_ID" column="C_ID">
<generator class="sequence"/>
</id>
<idbag name="myAs" table="CA_Rltn" cascade="save-update">
<collection-id type="java.lang.Integer" column="CA_ID">
<generator class="sequence"/>
</collection-id>
<key column="C_ID" not-null="true"/>
<many-to-many column="A_ID" class="A"/>
</idbag>
</class>

Name and version of the database you are using:
Oracle 10g


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.