Same effect as join fetch, but it keeps the fetch plan out of the JPQL and works with derived methods.
@EntityGraph(attributePaths = {"items", "customer"})
@Query("select o from Order o where o.status = :status")
List<Order> withItems(@Param("status") Status status);
// Also works on a derived method:
@EntityGraph(attributePaths = "items")
List<Order> findByCustomerId(Long customerId);
One query with two left joins,
and the same repository method still returns entities rather than a DTO.
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