Hibernate - (Part 1): Introduction

October 2016

Hibernate is a layer residing in the JVM to ensure the mapping Hidden Java objects in the JVM of (relational or data model). Hibernate also ensures the transfer of Java classes in the data entities, including data object in the entities and tables.
Hibernate also provides a language for manipulating objects mapped known as HQL. The goal to make Select, Update and Delete, using count, average..and other operations. HQL also has its limitations such as the use of the union operator. In the layer closest to the database, Hibernate uses JDBC (JDBC Template) to interact with the database.

The figure below depicts the components of Hibernate interacting with a database and the configuration components to provide the developer of a JAVA application with persistent objects to transport data between the objects and tables in the database.

Several tools for mapping (object/relational) exist in Hibernate community.

The Hibernate Session:

The loading of a mapped object of the database or update (Update, insert, delete) can be done if a Hibernate session is instantiated. The session layer is represented by the JAVA org.hibernate.Session interface.
For the developer of a Java application, the Hibernate activities starts after the following instruction:
session = sessionFactory.openSession ()
where sessionFactory is an object created by the application that uses the JDBC connection (or JNDI).
The Hibernate activities ends after method call
session.close ()
Between these two methods mentioned above, a transaction can be initiated by calling

Distribution, main classes and interfaces:

Hibernate version 3 can be downloaded from the link
The main jars are:
  • Ehcache-1.3.0.jar: Used by hibernate (second cache)
  • Hibernate-3.2.5.ga.jar: used by hibernate
  • Hibernate-annotations-3.3.0.ga.jar: Used for the jpa annotation
  • Hibernate-commons-annotations-3.3.0.ga.jar: Used for the jpa annotation
  • Hibernate-entitymanager.jar: Used for the jpa annotation
  • Hibernate-validator-3.0.0.ga.jar: for layer validation - hibernate validator (required fields, length, ..)

The .hibernate.cfg.Configuration class.
The Configuration constructor make use of the Hibernate configuration file (hibernate.cfg.xml.).
The org.hibernate.SessionFactory class
Virtually all Hibernate methods can trigger this exception.
Interface org.hibernate.SessionFactory
This is the first instance created:
new org.hibernate.cfg.Configuration ().configure ().buildSessionFactory ();
It allows reading hbm files (see the configuration section).
  • org.hibernate.Session class
  • org.hibernate.Query class
  • The classes that allows a developer to write the Hibernate query (HQL) using the JAVA objects.
  • org.hibernate.SQLQuery class
  • A class that allows a developer to write SQL queries.
  • org.hibernate.Transaction class

This is the Hibernate transaction object: commit() and rollback() functions.

Related :

This document entitled « Hibernate - (Part 1): Introduction » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.