< Prev
Next >

Hibernate With One-To-One Mapping

Today we are going to understand how to perform a one-to-one bidirectional mapping of objects between two Entity classes using Hibernate. To understand one-to-one mapping, let's take an example of two Entity classes - User_Details and Contact_Info, where objects of both Entity classes are stored in separated database tables and each object of User_Details is associated with a particular Contact_Info object.

A bidirectional one-to-one relationship is a two-way one-to-one relationship i.e. using a User_Details object, you could access its associated Contact_Info object and using a Contact_Info object, you could find the value of its associated User_Details object.

User_Details class is a parent class while Contact_Info is a child class, because first a user is created in User_Details and then his/her contact information is created in Contact_Info class by sharing the common primary key between the two tables i.e. user id and without a user there will be no need to create enter his/her information.

Let's put this example to work and make it easier for you to understand.

Note :

Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition