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: Help with one-to-one mapping.
PostPosted: Thu Jan 25, 2007 12:56 pm 
Newbie

Joined: Fri Jan 05, 2007 5:36 am
Posts: 16
Hi,

I'm new to NHibernate and have a lot of problem understanding how to set up a one-to-one relation.

I have a User class that contains a UserInformation and a UserProfile class.
Now I can't understand how I should mapp them with the keys.
I have tried to understand the documentation and also tried google but I couldn't solve it.

If someone could give me some easy instructions that I could follow or just an url to some place where they explain it.
Example code would also work!

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 12:25 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The most common way is to use the same value for all three IDs (so userID = 7 corresponds to userInformationID = 7 and userProfileID = 7). In this case, use id generator="foreign" in the UserInformation and UserProfile classes, and map the association as one-to-one on the User side, and <one-to-one constrained="true"> on the UserProfile and UserInformation sides.

If you're using foreign keys, so table UserInformation has UserInformationID and UserID columns that are not the same, then use <one-to-one property-ref="User"> on the User side (so that it knows to use the "User" property in UserInformation to find the matching object), and <one-to-one property-ref="UserInformation" constrained="true"> on the UserInformation side.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 10:03 am 
Newbie

Joined: Fri Jan 05, 2007 5:36 am
Posts: 16
After all my problems with this I need to thank you so much for helping me out!

Thanks!


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.