Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Hibernate Hibernate4.2 Hibernate Architecture

Related Tutorials


 
 

Share on Google+Share on Google+

Hibernate Architecture

Advertisement
This tutorial is taking about the Hibernate Architecture. In this tutorial you will learn about the architecture of Hibernate framework.

Hibernate Architecture - Understand the architecture of the Hibernate ORM framework.

Here we will discuss about the architecture of very extensible used Hibernate ORM framework. Hibernate is based on the Java technologies and it is used in the Java applications for developing the data access layer for the application. It has a layered architecture which allows the developers to use the mandatory core component and other components selectively. You can use full cream architecture of Lite architecture in our application.

Hibernate is ORM tool which uses the POJO's and then saves it into the database. The configuration file(s) and the annotations are used to provides the meta-data to Hibernate for mapping the POJO's with the database table.

Hibernate provides world class persistence services to the Java based application, more over it can work with both JSE and JEE based applications.

Steps to create Hibernate based applications

Step 1: Create database and tables

Step 2: Create POJO class

Step 3: Create mapping meta-data

Step 4: Write code to perform create, read, update and delete operations.

Hibernate uses the Java classes which represents the in the database. Hibernate uses the meta-data for mapping the instance variable in the class with the columns in the database.

You can use the Hibernate to perform operations like select, insert, update and delete the records in the table. Hibernate automatically generates the SQL query automatically to perform these operations against database.

Hibernate manages the transactions using JDBC Transactions or through JTA which can be configured in the application. You can make the transaction aware applications using Hibernate.

Following diagram shows how Hibernate works:

How hibernate Works

Configuring the Hibernate environment

Following are the configuration files of Hibernate:

hibernate.cfg.xml - This file is used to configure the database connection string and the other settings related to Hibernate runtime.

Annotations: Hibernate uses the JPA  annotations in the POJO class to map it to database table. You can use the annotations to map the instance variables to the table's columns.

Xml file for table mapping: Optional xml files can be used for mapping the class to table.

Services of Hibernate Framework

The main work of the Hibernate framework are:

Hibernate Connection management service- Hibernate manages the pool of database connections. You can use the Hibernate provided connection pool or use the more robust connection pool such as Apache DBCP.

Transaction management service- The Transaction Management Service is responsible for managing the database transaction. It allows user to execute multiple sql statements and then save all at time or rollback all of them.

Object relational mapping- The Hibernate core component  is responsible for O/R mapping services. It provides the API for saving, querying, updating and deleting the data from database.

Hibernate is a good tool for object relational mapping and you can use more robust connection pooling and transaction management services from third party.

Components of Hibernate Architecture

Following diagram shows the architecture of Hibernate framework:

architecture of Hibernate framework

Following is the description of Hibernate Architecture:

Following are the components of the Hibernate O/R mapping tool Architecture:

Hibernate SessionFactory: - In an application usually there is one instance of SessionFactory object. The instance of SessionFactory is used to get the session object. SessionFactory is thread safe and each session object is created in different thread. The instance of SessionFactory is immutable and once it is created its internal state does not change. The internal state includes the meta-data and the related O/R mapping.

Hibernate Session: The Session interface provides the API for Java application to interact with the database. Through this interface developers write the code for CRUD operation.

Hibernate Transaction: This is used to maintain the database transaction. Based on configuration it may use Transaction management component of Hibernate or JTA. I provides the API for efficient management of transactions.

Hibernate Query Language: The Hibernate Query Language is also known as HQL and it like simple SQL, but operates on the POJO class..

Hibernate Criteria: Criteria query is used to query the database based on set of criterion.

In this session you have understood the architecture of Hibernate Framework.

Check more Hibernate 4.2 tutorials.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: December 19, 2013

Related Tutorials

Discuss: Hibernate Architecture  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com