Caching in Hibernate is a multi-level system, and understanding its architecture is critical for application performance. The golden rule: caching is disabled by default (except for the first-level cache), and it must be enabled consciously for specific data. The system consists of three independent layers, each with its own area of responsibility.
First-Level Cache
This is the foundation that cannot be disabled. It is always active and bound to a specific session ( Session / EntityManager ).
What it is: Essentially, this is the Persistence Context. All entities loaded within a single session are placed into this cache.
Scope: Only within a single session (usually a single transaction).…