-->
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: help with <one-to-one> association
PostPosted: Tue Oct 07, 2003 2:22 pm 
Newbie

Joined: Tue Oct 07, 2003 2:05 pm
Posts: 2
Hi,
I'm starting with Hibernate and I manage to solve all my problems with <many-to-one> associations but <one-to-one> seems very confusing for me.
I need help to use Hibernate with <one-to-one> associations. I read in the Hibernate reference that the tables should share the same primary-key values, but they are required to have the same name(and the name must be the same in the database, in my classes or in both)?
Can I have the primary and the foreign key in separated fields or they should be the same field?
I read all kinds of helps, faqs and manuals all over the internet but I couldn't be able to solve my doubts.
If someane have any example with mappings, classes and schemas of database I would aprecciate it.

Thanks in advance,
F


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 5:50 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:41 am
Posts: 21
I ran into the same situation and reverted to just using a many-to-one which worked for what I wanted.

In case it's any use to you, there is the property-ref attribute of the one-to-one element which might help in your circumstances.

(It's a fairly recent addition so you may need to be using 2.1bx)

John


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 6:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
One-to-one mapping has two mode of operation.
1) The link is across the primary keys of the two domain objects concerned. This is the only option for Hibernate <= 2.0 version.
2) The link used a foreign key. This is a new feature in Hibernate 2.1 where, in a bi-directional senario, one side will use the property-ref that represent the foreign key and the other is mapped with a many-to-one.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 8:56 am 
Newbie

Joined: Tue Oct 07, 2003 2:05 pm
Posts: 2
Thanks for the answer, i'll give a try for the 2.1.beta4 version.

I also found the answer for my first question. In all the examples I found over the Internet the tables and classes related in <one-to-one> association always have the same name in both classes and tables but this is not mandatory, the only thing they must share is the same value. Thus you can have ids with different names in your classes, tables or both as long as they share always the same value. This is not what I intend to have in my application, so I'll use the 2.1.beta4 version.


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.