Hibernate Pagination: Missing Default Page Size Constraint
0 reputation · 27 Jan 2024, 19:42 UTC
Goal
To clarify the behavior of Hibernate ORM 6.x when a query is executed without an explicit setMaxResults() call, and to determine whether a default page size should be enforced.
Context
Hibernate currently offers no documented default page size. Developers must manually set setMaxResults() to limit result sets. This lack of a constraint can cause unbounded result fetches, leading to memory exhaustion or performance regressions, especially when combined with distinct projections and pagination parameters.
Uncertainty
It is unclear whether Hibernate should impose a maximum default page size, what that limit should be, and how such a limit could be exposed without breaking existing code that relies on unlimited fetches. Additionally, the interaction between distinct projections, ordering, and pagination remains undocumented, raising questions about result stability.
Specific Questions
- Should Hibernate enforce a maximum default page size for queries that omit
setMaxResults(), and if so, what value would be appropriate? - How can this default or maximum page size be configured per session or globally without requiring code changes?
- What is the documented behavior when combining
distinctprojections with pagination, and how does ordering affect the returned subset?