Hibernate pagination result consistency and order limits
0 reputation · 16 Mar 2026, 15:29 UTC
Hibernate implements pagination using the setFirstResult() and setMaxResults() methods, which translate to database-specific LIMIT and OFFSET clauses. To ensure a stable window of results across multiple page requests, an ORDER BY clause is typically required in the underlying query.
Without an explicit sort order, the database may return rows in an inconsistent sequence across different executions, potentially causing records to be skipped or duplicated between pages. This behavior is particularly relevant when integrating the legacy Query API with Hibernate 6.x Criteria API features.
Does Hibernate provide a mechanism to enforce a default deterministic sort order at the session or query level when a specific ORDER BY clause is omitted? What are the performance implications of relying on implicit ordering when using high offset values?