In this tutorial we are going to describe hibernate architecture with example.
Hibernate Architecture :
It is layered architecture. So you are away from the underlying
APIs. Hibernate is written in java and you can configure it in two ways-
first by using configuration file named hibernate.cfg.xml and another by using *.hbm.
Diagram : Here is diagram of Hibernate architecture.
The above diagram shows how hibernate uses database and configuration data to provide persistent object to your application.
JDBC is not the only technology used between Hibernate and database server
but there are more java APIs like JTA(Java Transaction
API),JNDI(Java Naming and Directory Interface).
Now we are going to give you brief description of architecture -
Hibernate Configuration :
Configuration class perform two operations. You can say Configuration class
has two component-database connection and class mapping setup.
The first component is handled through one or more configuration files supported by Hibernate. These files are hibernate properties and hibernate.cfg.xml.
Second component that is class mapping, it creates the connection between java classes and database tables.
Hibernate SessionFactory :
For SessionFactory import org.hibernate.SessionFactory.
SessionFactory is factory for Sessions and is created in your configuration
When your application start ,it is created. For each database ,there is one SessionFactory.
If you are using more than one database you need to create multiple SessionFactory object. It is thread safe object.
It also maintains second level cache of data that is reusable between transactions at a process or cluster level but it is optional.
Hibernate Session :
For Session Object import org.hibernate.Session. It is used
for database connection. It is very lightweight and
single-threaded. It lives for short time, represents conversation between the application and the persistent store.
Session object is used for saving and retrieving persistent objects. Session object is not thread safe so do not open it for long time.
You can create and destroy as your need.
Hibernate Transaction :
For Transaction import class org.hibernate.Transaction.It is
Transaction is single threaded and short-lived object ,used for a unit of work with the database.
Most of the RDBMS supports transaction functionality. Transaction manager handle your transactions.
Hibernate Query :
Hibernate provide simple SQL ,native query and HQL for performing different database operations. At last execute query to complete your operation.
Hibernate Criteria :
Hibernate provide a high object oriented concept of criteria. Criteria
objects are used to perform database operations
under object oriented concepts.
Recommend the tutorial