Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Introduction To Hibernate 4.0

Hibernate is a Object-relational mapping (ORM) tool for Java. It was initiated by Gavin King in 2001. ORM methodology is used to map classes to tables, class instances is mapped to rows and attributes are mapped to table columns. It also map data types of Java to SQL data types.


How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code

Introduction To Hibernate 4.0

Hibernate is a Object-relational mapping (ORM) tool for Java. It was initiated by Gavin King in 2001. ORM methodology is used to map classes to tables,  class  instances is mapped to rows and attributes are mapped to table columns. It also map data types of Java to SQL data types.

Hibernate is a persistence framework which used to store and fetch data from Java environment to database table. Persistence is a storing  process of data to permanent storing medium like SQL database and fetching back to any time which may be after ending the process which stores data to this table.

Here is the video tutorial of: "Introducing the Hibernate 4 framework to beginners"

Advantages of using Hibernate

  • It handles the mapping of Java class to the database table using annotation or XML file. You don't need to write any code to map it.

  • Java objects can be store directly and fetch from the database using  it's easy APIs.

  •  Later on , if there is a change in any table or Database, you need to change only the XML file and the Java Class related to the table.

  • You don't need to take care of SQL data type, you just need to work on familiar Java data types.

  • It doesn't need any application server to function.

  • Reduce database access complexity by easy fetching techniques.

  • It has easy and simple query for data access.

Supported Database

Hibernate supports following RDBMS :

  • MySQL

  • Oracle

  • PostgreSQL

  • FrontBase

  • DB2/NT

  • Microsoft SQL Server Database

  • Sybase SQL Server

  • Informix Dynamic Server

  • HSQL Database Engine 

Hibernate Architecture

The figure given below represents the architecture of Hibernate :


Hibernate Configuration

The configuration of Hibernate is handled by the instance of org.hibernate.cfg.Configuration . It symbolizes the complete mapping between Java data types to the SQL database or database table. It is used to construct org.hibernate.SessionFactory . Various XML mapping files or Java Annotations compilation build these mapping.

Following 3 types of configuration is provided by the Hibernate :

(1) hibernate.cfg.xml

This XML file resides in root of application's CLASSPATH. This file constitutes hibernate configuration.

A sample hibernate.cfg.xml file is given below :

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">thread</property>

<mapping class="worker.Worker" />



This property file contains the key-value pair for different hibernate configuration.

The sample file is given below :

hibernate.connection.url= jdbc:mysql://
hibernate.transaction.factory_class = \
hibernate.transaction.manager_lookup_class = \
hibernate.dialect = org.hibernate.dialect.MySQLDialect

(3) Programmatic configuration

This is the manual configuration which needs to be done in Java file. We can get an instance of org.hibernate.cfg.Configuration directly by specifying mapped class using  .addClass( ).

Configuration cfg = new Configuration()

Building a SessionFactory

After creating instance of org.hibernate.cfg.Configuration , you can create instance of SessionFactory as follows:

SessionFactory sessions = cfg.buildSessionFactory();

Creating Session instance

 Between database table and application, Session represents a communication channel. From SessionFactory , Session can be created as follows:

Session session = sessions.openSession();



Share on Google+Share on Google+

Introduction To Hibernate 4.0

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



Discuss: Hibernate 4 Introduction  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 20, 2012

how and from where i can find 9 jar file to set a classpath how ican download jar files
March 27, 2014
Hibernate 4

Why no annotation? Should be light weighted.