-->
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.  [ 5 posts ] 
Author Message
 Post subject: one-to-one mapping with different primary keys
PostPosted: Wed Aug 31, 2005 8:25 pm 
Newbie

Joined: Wed Aug 31, 2005 8:18 pm
Posts: 18
Hi,

I am new to Hibernate, my application needs one-to-one mapping of two tables having different primary keys. Please let me know, how to do this.

Thanks,

Kum


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:28 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
assuming...

Table A with column id
Table B with column id and fk (foreign key to A.id)

Then, the mapping could be
<class name="A" table="A">
<id name="id" type="integer"/>
<one-to-one name='to' class="B" property-ref="fk"/>
</class>

<class name="B" table="B">
<id name="id" type="integer"/>
<property name="fk" type="integer"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 04, 2005 11:21 am 
Newbie

Joined: Wed Aug 31, 2005 8:18 pm
Posts: 18
Thanx a lot Anar.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 2:54 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
What if in class B
id and fk columns form the composite key and fk column is also the foreign key referencing table A?
How will the mapping look like


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 4:32 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
But how can we do this with annotation ?
I am using the hibernate annotation documentation that says to do
this :
Code:
@Entity
public class Body {
    @Id
    public Long getId() { return id; }

    @OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    public Heart getHeart() {
        return heart;
    }
    ...
}
           

@Entity
public class Heart {
    @Id
    public Long getId() { ...}
}
           

This seems to be very simple. But it does not work !
I have a cannot simultaneously fetch multiple bags exception ?


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