Hibernate Basics
Hibernate Setup
Hibernate Notes
Hibernate Mapping using XML
Hibernate Architecture Tutorial
Hibernate architecture includes many components like persistant object, session factory, transaction factory, connection factory, session, transaction and others. The architecture is made up of four layers.
- Java application layer
- Backend api (Persisitance) layer
- Hibernate framework layer
- Database layer
Let's look at the diagram below.
Following is the high level architecture of hibernate with mapping and configiration files.
Hibernate framework consists of many objects line session factory, session and transaction along with Java API like JDBC (Java database connectivity) and JTA (Java transaction api).
Components of Hibernate Architecture
SessionFactory
The SessionFactory provides factory of session and client of ConnectionProvider. It stores second level cache (optional) of data. The org.hibernate.SessionFactory is interface and provides factory method to get the object of session.
Session
The session object provides methods to store data in the database. It is a short-lived object and wraps the JDBC connection. It is factory of Transaction, Query and Criteria. It also holds first-level cache (mandatory) of data. The org.hibernate.Session interface provides methods such as insert, update and delete. It also provides factory methods for Transaction, Query and Criteria.
Transaction
The transaction object is alos short-lived which specifies the atomic unit of work. It is optional. The org.hibernate.Transaction interface provides methods for transaction management.
ConnectionProvider
ConnectionProvide is a factory of JDBC connections. It abstracts the application from DriverManager or DataSource. It is optional. It is not exposed to application, but it can be extended by the developer.
TransactionFactory
It is a factory of transactions and is optional.