N+1 problem

The N+1 problem occurs when you load N entities and each one then triggers its own query for a lazy relationship: 1 initial query + N queries. You fix it with grouped loading: JOIN FETCH in JPQL, @EntityGraph, or @BatchSize. You spot it by logging the SQL queries.

Example

select c from Client c join fetch c.commandes

Related concepts

The whole glossary