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.  [ 1 post ] 
Author Message
 Post subject: Small doubt on a one-to-one relationship
PostPosted: Fri Mar 18, 2005 9:21 am 
Beginner
Beginner

Joined: Sun May 16, 2004 3:53 pm
Posts: 47
Location: Belo Horizonte, Brazil
Hibernate version:2.x

I haven`t used Hibernate for a while. Right now I`m just trying to remeber things.
I was looking at some docs about a one-to-one mapping.
Basically, all docs mentions 2 kind of one-to-one relations. The one I`m interested is: A bidirectional one-to-one association on a foreign key.

This example for a bidirectional one-to-one association on a foreign key I took from hibernate.org (http://www.hibernate.org/hib_docs/v3/re ... ml_single/).

Code:
create table Person ( personId bigint not null primary key, addressId bigint not null unique )
create table Address ( addressId bigint not null primary key )


Code:
<class name="Person">
    <id name="id" column="personId">
        <generator class="native"/>
    </id>
    <many-to-one name="address"
        column="addressId"
        unique="true"
        not-null="true"/>
</class>

<class name="Address">
    <id name="id" column="addressId">
        <generator class="native"/>
    </id>
   <one-to-one name="person"
        property-ref="address"/>
</class>


I don`t quite undesrtand why couldn`t we have one-to-one tags on both sides (both mapping files). Why do we have to create a many-to-one tag on the other side??? I know that this will have on effect, but couldn`t i use
2 one-to-one tags???
Thanks.


Leandro Melo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.