Notes – Hibernate Architecture
Hibernate architecture is designed to manage all database-related operations in a structured and efficient way.
It works as a bridge between Java objects and relational database tables.
Core Layers of Hibernate Architecture
Hibernate has four key layers:
| Layer | Description |
|---|---|
| Java Application | Your main Java code that uses Hibernate for DB operations. |
| Hibernate Framework | Core Hibernate APIs like Session, Transaction, Query, etc. |
| JDBC/Database Layer | Low-level JDBC API and actual database system. |
| Configuration Layer | Contains mapping and setup details (hibernate.cfg.xml, annotations). |
Hibernate Architecture Components
| Component | Role in Architecture |
|---|---|
Configuration | Reads configuration files and sets up Hibernate. |
SessionFactory | Creates sessions. Heavy objectโshould be created only once. |
Session | Lightweight, short-lived object to interact with DB. |
Transaction | Manages a unit of work like commit or rollback. |
Query / HQL | Executes queries on Java objects using HQL or native SQL. |
Persistence | Refers to storing and retrieving Java objects in/from the database. |
Hibernate Workflow (Simple Flow)
- Application loads configuration.
SessionFactoryis created once at startup.Sessionis opened when DB interaction is needed.Transactionis started to ensure atomic operation.- SQL or HQL queries are executed via
Session. - Transaction is committed or rolled back.
- Session is closed.
Diagram (Text Representation)
Java Application
โ
Configuration โ SessionFactory
โ
Session
โ
Transaction
โ
JDBC / Database
