تخطَّ إلى المحتوى

Missing Eager Load (ARCH4051)

هذا المحتوى غير متوفر بلغتك بعد.

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.

@Query("SELECT a FROM Author a")
List<Author> findAllAuthors();
List<Author> authors = findAllAuthors();
authors.forEach(a -> render(a.getBooks())); // lazy books -> N queries
@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.