Missing Eager Load (ARCH4051)
Esta página aún no está disponible en tu idioma.
Key java.orm.missing-eager-load · Severity warning · Category orm
Iterating related data from a query that did not declare eager loading (JOIN FETCH / entity graph) triggers N+1 at runtime. Eager-load the association explicitly at the query level.
Incorrect
Section titled “Incorrect”@Query("SELECT a FROM Author a")List<Author> findAllAuthors();
List<Author> authors = findAllAuthors();authors.forEach(a -> render(a.getBooks())); // lazy books -> N queriesCorrect
Section titled “Correct”@Query("SELECT a FROM Author a JOIN FETCH a.books")List<Author> findAllWithBooks();
List<Author> authors = findAllWithBooks();authors.forEach(a -> render(a.getBooks()));Add JOIN FETCH or @EntityGraph to the query when the related collection will be consumed.