I am beginner to hibernate, just have a doubt, Could you please help me to design following relations
Employee table
`Eid - primary key`
`ename`
`esal`
Address
`aid` - primary key
addressLine1
city
state
eid - foreign key of employee table
It is having one to one relationship, Employee has only one address.
How can I manage primary and foreign key in one table using one-to-one mapping in hibernate. What could be the xml mappings for this relation in hibernate.
Tried
employee
<class name="Employee" table="employee" schema="system">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="name" column="ename" />
<property name="designation" column="designation" />
<one-to-one name="address" class="Address" cascade="all"/>
</class>
Address
<class name="Address" table="address_details" schema="system">
<id name="eid" column="id">
<generator class="increment">
</generator>
</id>
<property name="address" column="address"></property>
<property name="city" column="city"></property>
<property name="state" column="state"></property>
<one-to-one name="emp" class="Employee" column="eid"></one-to-one>
</class>
You can find tons of examples on the internet. This particular model is even showcases here: https://en.wikibooks.org/wiki/Java_Persistence/OneToOne