Share on Google+Share on Google+

Hibernate O/R Mapping

In this tutorial you will learn about the Hibernate O/RM (Object/Relational Mapping).

Hibernate O/R Mapping

In this tutorial you will learn about the Hibernate O/RM (Object/Relational Mapping).

O/RM itself can be defined as a software or product that represents and/or convert the data between the application (written in Object-Oriented Language) and the database. In other words we can say O/RM maps an object to the relational database table. Hibernate is also an O/RM and is available as open source project. To use Hibernate with Java you will be required to create a file with .hbm.xml extension into which the mapping information will be provided. This file contains the mapping of Object with the relational table that provides the information to the Hibernate at the time of persisting the data. ORM abstracts the application from the process related to database such as saving, updating, deleting of objects from the relational database table.

We will understand the above concept with the help of an example

Example :

package roseindia;

public class Employee
	private long empId;
	private String empName;
	public Employee() {
	public long getEmpId() {
          return this.empId;
	public void setEmpId(long empId) {
	  this.empId = empId;
	public String getEmpName() {
	  return this.empName;
	public void setEmpName(String empName) {
	  this.empName = empName;


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<class name="roseindia.Employee" table="employee">
<id name="empId" type="long" column="Id" >
<generator class="assigned"/>
<property name="empName">
<column name="Name" />

The figure given below demonstrate you how ORM abstracts the application to the database related process and vice-versa :

The above figure demonstrates that an ORM abstracts the both in respect to database how an application tries to persist the data and in respect to an application that how objects are stored in database.


Posted on: March 27, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Hibernate O/R Mapping  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image