-->
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: one-to-many, based on multiple keys?
PostPosted: Wed Sep 16, 2009 10:07 pm 
Newbie

Joined: Mon Jul 27, 2009 3:34 pm
Posts: 3
Lets assume I have two tables
Code:
Table tA
    ID
    ID2
    SomeColumns...
Table tB
   ID
   ID2
   SomeOtherColumns...


I am looking to create a Object let's call it ObjectA (based on tA), that will have a one-to-many relationship to ObjectB (based on tB). In my example however, I need to use the combination of ID and ID2 as the foreign key. If I was writing SQL it would look like this:

select tB.* from tA, tB where tA.ID = tB.ID and tA.ID2 = tB.ID2;

I know that for each ID/ID2 combination in tA I should have many rows in tB, therefor I know it's a one-to-many combination. Clearly the below set is not sufficient for such mapping as it only takes one key into account.
Code:
<set name="A2" table="A2" generic="true" inverse="true" >
  <key column="ID" />
  <one-to-many class="A2" />
</set>


Thanks.


Top
 Profile  
 
 Post subject: Re: one-to-many, based on multiple keys?
PostPosted: Thu Sep 17, 2009 2:06 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look here:

http://nhforge.org/doc/nh/en/index.html#components-compositeid

_________________
--Wolfgang


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.