-->
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-toone mapping question
PostPosted: Mon Jan 24, 2005 2:30 pm 
Newbie

Joined: Mon Jan 24, 2005 2:22 pm
Posts: 4
Hi,

Got a question on one-to-one mapping. According to Tom Sedge's tutorial (http://www.xylax.net/hibernate/), the one-to-one mapping requires a shared PK between two persistent classes. However, that's not the usual way we implement in database (we usually set up a foreign key in one of the tables). I was wondering, is it (the shared PK) REQUIRED or is just one of the ways to implement one-to-one mapping?

I did see another example from "http://www.meagle.com:8080/hibernate.jsp" that does not use a shared key, but to include an object from the second class to the first class.

Thanks for your help.

Lilly


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 2:34 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Did you try the reference documentation or Hibernate in Action?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 6:03 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
Lilly,

Tom is not saying that you have to share the FK as in they both have the same foreign key value. He is saying that they will both have the same primary key. As in, both primary keys will have the same value.

Hibernate offers a couple of approaches for one-to-one mapping.

The 'reference documentation' is particular effective in explaining this. Admittedly, it's hard at first to know what you're reading.

Anyway -

Using a one-to-one mapping one of the things you can do is specify that one of the mappings use a 'foreign' id generator. This will tell hibernate that it must use the same primary key for this entity that it uses for the other mapped entity (this is quite clear I'm sure ;) )

ANOTHER approach, the one I prefer, is to use a many-to-one mapping which will result in the more familiar Relational approach you discussed. It will put a foreign-key on the table for which you are currently mapping to the table holding the other thing you're mapping.



Hopefully this provides a bit of help

_________________
Joe W


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 6:14 pm 
Newbie

Joined: Mon Jan 24, 2005 2:22 pm
Posts: 4
Thanks to both of you. That helps a lot. You also help me to realize to read the reference documentation more thorough :)).

Lilly


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.