OneToOne Mapping in Hibernate using Annotations

OneToOne Mapping in Hibernate using Annotations:

In this example lets see how to implement OneToOne mapping in hibernate using Annotations.

There are 3 types of Mappings in Hibernate,
1. OneToOne
2. ManyToOne
3.ManyToMany

Here lets see an example of OntToOne Mapping.

In our example we are going to have 2 entities Address and Employee.  When we enter the employee details there will a column that points to another table ID where the related address of that employee is stored.

op1

Once you go through this example, you can understand clearly.

Structure:
Structure

hibernate.cfg.xml

NewHibernateUtil.java

Address.java

Employee.java

Execution.java

Output:

op1

Employee Table
op3

Here we can see that a new column “Address_Joining” has been included in table and it points to ID: 1 of Address table

op2

Here we can see the address table with pointing id:1

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *