Hibernate Architecture


There are 4 basic layers in hibernate architecture i.e.
1. Java application layer
2. Backend layer
3. Hibernate framework layer
4. Database layer




The Hibernate framework contains following levels:

                  

Java Application:
The java application uses the hibernate framework .

Persitent Class Object:
Hibernate provides transparent persistence for Plain Old Java Objects (POJOs). The only strict requirement for a persistent class is a no-argument constructor.

SessionFactory:
SessionFactory is actualy an interface that extends Referenceable and Serializable.
The org.hibernate.SessionFactory interface provides factory method to get the object of Session.
An application usually has a single SessionFactory.
The Configuration class can be used to create SessionFactory object which serves as a factory class that creates Session objects.
It holds second level cache of data.

Session:
The org.hibernate.Session interface provides methods to insert, update and delete the object.
A Session is used to get a physical connection with a database.
The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database. Persistent objects are saved and retrieved through a the Session object.
It is factory of Transaction, Query and Criteria. It holds a first-level cache (mandatory) of data.

Transaction:
The org.hibernate.Transaction interface provides methods for transaction management.
A transaction represents a unit of work. If you want the database to do some work for you, then we need to start a transaction.

ConnectionProvider:
It is a factory of JDBC connections ie provide the connection between jdbc and database. It abstracts the application from DriverManager or DataSource.