beginner~3h

Hibernate Architecture — SessionFactory, Session, EntityManager

Every Hibernate operation flows through one of two objects with a deliberately asymmetric cost: an expensive, one-time factory, and a cheap, per-request session — understanding this split is foundational to everything from here on.

Learning objectives

  • Explain the cost and thread-safety difference between SessionFactory/EntityManagerFactory and Session/EntityManager.
  • Describe how Spring Boot manages this lifecycle transparently via @Transactional.
  • Identify a manual session-management mistake (sharing across threads, recreating the factory per request) and explain why it's wrong.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.

Hibernate Architecture — SessionFactory, Session, EntityManager

Next Step

Continue to The Persistence Context — First-Level Cache, Dirty Checking & Flush← Back to all Spring Data JPA & Hibernate Mastery chapters