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