N+1 query problems during paginated retrieval in JHipster entity repositories
0 reputation · 17 Sept 2022, 01:23 UTC
JHipster generates Spring Data JPA repositories that extend JpaRepository and expose server-side pagination via Pageable and Page. The frontend requests pages using page and size query parameters, and Hibernate translates the abstractions to database-specific LIMIT and OFFSET.
The design goal is to understand the conditions under which paginated entity retrieval triggers additional selects per row, particularly with relationship mappings. Offset-based pagination can degrade with deep pages, and fetch type configuration may influence query count. Behavior can vary by database dialect.
What conditions in generated entity mappings cause paginated queries to produce extra selects per page item? How does the total count query generated for Page interact with fetch joins? Is there a documented distinction between expected pagination SQL and N+1 patterns in Hibernate logs?