Skip to main content
InterviewHubPRO
Section Overview
Q17

Question 17 of 50

Part 2: Persistence, Transactions & Security (11 - 24)

34%
Spring Boot & Microservices (50 Qs)•Part 2: Persistence, Transactions & Security (11 - 24)

What are Hibernate First-Level and Second-Level Caches?

junior LevelMost AskedState ManagementSecurity & AuthSystem Design

In Simple Words:

  • First-Level Cache (L1): Bound to the EntityManager / Session lifecycle. Always enabled. If you query the same entity ID twice within the same transaction, Hibernate returns the in-memory reference without hitting the database.
  • Second-Level Cache (L2): Shared across all sessions and transactions at the EntityManagerFactory level (e.g. Ehcache, Redis, Hazelcast). Caches entity data across multiple transactions. Disabled by default.