Infographic: calling getBooks() in a loop after findAll() produces 1 main query plus N relation queries; below it the four fixes — JOIN FETCH, @EntityGraph, batch fetching and DTO projection — with detection tips and rules of thumb
Aug 8, 2026 · 10 min

The N+1 Query Problem: A Silent Performance Trap in ORMs

You load the main records with one query, then run one more query for every relation. How the N+1 problem happens, how to notice it, and which fix to use when.