Hibernate Pagination and Collection Fetching Memory Warning
0 reputation · 09 Oct 2023, 00:32 UTC
When implementing pagination using setFirstResult() and setMaxResults(), Hibernate typically delegates the limit and offset logic to the database dialect. However, this behavior changes when the query involves join fetching of collections.
The goal is to retrieve a paginated subset of entities while simultaneously loading their associated collections to avoid N+1 select issues. The constraint is that Hibernate may trigger a HHH000104 warning, indicating that pagination is being applied in-memory rather than at the database level.
- Under what specific mapping conditions does Hibernate decide to perform in-memory pagination instead of generating a database-level LIMIT/OFFSET clause?
- What are the performance implications for the JVM heap when the result set exceeds the
setMaxResultsvalue before the in-memory filter is applied?