Hibernate: LazyInitializationException means the session already closed

The proxy needs an open session to load. Touching it in the view layer is too late.

Code
@Transactional(readOnly = true)
public Order load(Long id) {
    return repo.findById(id).orElseThrow();   // session closes at return
}

// Later, in the controller:
order.getItems().size();   // BOOM
Output
org.hibernate.LazyInitializationException:
failed to lazily initialize a collection of role: Order.items -
no Session

Fix: fetch what you need inside the transaction, or map to a DTO there.
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