Hibernate: The first-level cache is the persistence context

Within one transaction, loading the same id twice hits the database once - and returns the identical object.

Code
@Transactional
void demo() {
    Order a = em.find(Order.class, 1L);   // SELECT
    Order b = em.find(Order.class, 1L);   // no SQL
    System.out.println(a == b);
}
Output
Hibernate: select ... from orders where id=?
true
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11