Hi,
Following is the example taken from the hibernate reference:
Code:
<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
</class>
<class name="Address">
<id name="id" column="personId">
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<one-to-one name="person" constrained="true"/>
</class>
Code:
create table Person ( personId bigint not null primary key )
create table Address ( personId bigint not null primary key )
In the xml above, no association with address is there in the person class mapping. Then how can the address be accessed from a Person object?
Moreover, in another example of one-to-one:
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>
</class>
Code:
create table Person ( personId bigint not null primary key, addressId bigint not null unique )
create table Address ( addressId bigint not null primary key )
why do we have to make it using many-to-one mapping? why not using one-to-one?