Hibernate Architecture (original) (raw)

Last Updated : 20 Apr, 2026

Hibernate is a framework which is used to develop persistence logic which is independent of Database software. In JDBC to develop persistence logic we deal with primitive types. Whereas Hibernate framework we use Objects to develop persistence logic which are independent of database software.

Hibernate Internal Architecture

Hibernate Architecture Shows how Java objects interact with the database through Hibernate layers and APIs.

Hibernate Architecture

Configuration

It activate Hibernate Framework Configuration cfg = new Configuration();
it read both cfg file and mapping files cfg.configure();

SessionFactory

buildSessionFactory() method gathers the meta-data which is in the cfg Object.
SessionFactory uses the configuration metadata to manage database connections through connection providers and pooling mechanisms.
SessionFactory factory = cfg.buildSessionFactory();

Session

Session session = factory.openSession();

**openSession(): is a method provided by the SessionFactory that creates and returns a new Session instance. This session is not bound to any transaction or context and is independent of any ongoing transactions in the application.

**getCurrentSession: it returns a Session bound to the current context, which is usually managed by a transaction manager or a framework like Spring. It requires configuration like hibernate.current_session_context_class (e.g., thread or Spring-managed context).

Session session = sessionFactory.getCurrentSession();

Transaction

Transaction tx=session.beginTransaction();
tx.commit();

Query

Criteria

Flow of working during operation in Hibernate Framework

The below image showing how the hibernate application internally works:

hibernate_framework

Hibernate flow of working

Stage I: Transient State

Stage II: Persistent State

Stage III: Detached State

Stage IV: Removed State

Stage V: Data Flow to Database