Within one transaction, loading the same id twice hits the database once - and returns the identical object.
@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);
}
Hibernate: select ... from orders where id=?
true
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