-->
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: one-to-one with composite id
PostPosted: Fri Jul 07, 2006 5:56 am 
Newbie

Joined: Wed Oct 20, 2004 6:22 am
Posts: 9
Hibernate version:
3

I have an existing databse schema which I can't change and I am wondering how to map teh following relationship :
I have the following class :
public class User implements java.io.Serializable {

private Long addressId;
private Long organisationId;
......

and the other class :
public class Testing implements java.io.Serializable {
private User user;
........

The class teting needs a composite key of addressId and organisationId
this is how the tables are in the db

How could I map that relationship in hibernate. It is a one to one with composite id ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 8:41 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Refer to this on one-to-one mapping section

http://www.hibernate.org/hib_docs/v3/re ... tions.html

you can also refer to hibernate in action book, page 330, which deals with, showing association using composite keys

hope this helps

sudhir


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 10:24 am 
Newbie

Joined: Fri Jun 30, 2006 5:30 pm
Posts: 13
You need to use a class for your composite key in order to get Hibernate to work. Just use the same class for both objects, ie:

Code:
        <composite-id name="key" class="com.company.MyKey">
           <key-property name="addressId" type="long" column="ADDRESS_ID"/>
           <key-property name="organizationId" type="long" column="ORG_ID"/>
        </composite-id>



Then just define the <one-to-one ..> in the mapping files for the object(s)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 1:31 pm 
Newbie

Joined: Wed Oct 20, 2004 6:22 am
Posts: 9
Thanks a lot for that,

Now, I have created my composite key and understood that I need to use the key object in both places. Now my problem is my first object need a generator to create one of the id .
one of my first object key is actually generated by a genrator and the other one is from a many to one relationship. How would that composite id be written in the mapping doc ?


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.