-->
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.  [ 4 posts ] 
Author Message
 Post subject: can you create a join with a composite key in hibernate...
PostPosted: Thu Dec 28, 2006 2:12 pm 
Newbie

Joined: Fri Dec 15, 2006 5:49 pm
Posts: 16
can you create a join with a composite key in hibernate... I have this oracle table that has a composite key that is two of its fields for the primary key but I want to be able to join it to another table that also has these keys... but I am having trouble creating such a join... the table that has the table that has the composite key has a one to may relationship with the other table....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 3:30 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
No problem, Hibernate can do it. Show us the mapping you did... Even if it doesn't work yet...

I'd advice you to first create a javabean class that will have only those two properties and their getter/setter. This class will obviously represent the primary key/foreign key. You'll then use it in the mapping, read the reference doc:

* How to map a composite-id: http://www.hibernate.org/hib_docs/v3/re ... ompositeid
This will give you a mapping like:
Code:
<composite-id class="YourId" mapped="true">
        <key-property name="yourFirstProp"/>
        <key-property name="yourSecondProp"/>
</composite-id>


* How to use it in a foreign-key mapping. In your case, you say this is a one-to-many relationship, so it means that it's kind of a collection mapping that you need. So you simply need to map a usual collection on the "one" side, and map the foreign-key on the "many" one (quite in a way close to what you'd with SQL: the constraint can only be from the collection elements to the container, not the contrary).

Declare a field of YourId type in the child element and map it this way:
Code:
<many-to-one name="region" >
           <column name="yourFirstProp" not-null="true" />
           <column name="yourSecondProp" not-null="true" />
</many-to-one>


Hope this helps, bye suzie.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: how do create the getter and setter for the join
PostPosted: Mon Mar 19, 2007 6:14 pm 
Newbie

Joined: Fri Dec 15, 2006 5:49 pm
Posts: 16
how do create the getter and setter for the join


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 6:25 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Look at the ref doc. Then ask precise questions.
Bye.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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