-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping two tables on their primaryKeys with annotations
PostPosted: Tue Apr 29, 2008 7:05 pm 
Newbie

Joined: Tue Apr 29, 2008 7:01 pm
Posts: 4
Hi guys,

I have two tables:
User -> pk is ID
UserDetail -> pk is USERID

How can I map a @OneToOne relationship inside User to UserDetail?

Is this even the best/most efficient way of doing this?

Thank you for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 5:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

If I understand correctly you want to map a one to one relationship using shared primary keys. You will have to use @OneToOne together with @PrimaryKeyJoinColumn. See http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#d0e1001.

You are responsible for setting the right id in UserDetails. If you have a bidirectional relationship, meaning the UserDetails has a reference back to User you can also utilize the @GenericGenerator annotation - http://www.i-proving.ca/space/Technologies/Hibernate/Hibernate+Annotation+Examples/One+to+One+Mapping.

Hopefully this was not too far off from what you actually asked ;-)

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 9:19 pm 
Newbie

Joined: Tue Apr 29, 2008 7:01 pm
Posts: 4
thank you hardy!! that helps!


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