It also lets the driver and some databases route to a replica. Cheap win on every query method.
@Transactional(readOnly = true)
public List<Order> recent() {
return repo.findTop50ByOrderByPlacedAtDesc();
}
Hibernate skips taking snapshots of loaded entities,
so a 5,000-row read allocates far less and never issues a stray UPDATE.
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