hibernate/hibernate-orm · error · HibernateException
setFirstResult() or setMaxResults() specified with collectio
Error message
setFirstResult() or setMaxResults() specified with collection fetch join (in-memory pagination was about to be applied, but 'hibernate.query.fail_on_pagination_over_collection_fetch' is enabled)
What it means
Error "setFirstResult() or setMaxResults() specified with collection fetch join (in-memory pagination was about to be applied, but 'hibernate.query.fail_on_pagination_over_collection_fetch' is enabled)" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java:1507
parameterBinding.setBindValue( binding.getBindValue(), explicitTemporalPrecision );
}
}
else {
final var bindType = binding.getBindType();
if ( binding.isMultiValued() ) {
parameterBinding.setBindValues( binding.getBindValues(), bindType );
}
else {
parameterBinding.setBindValue( binding.getBindValue(), bindType );
}
}
parameterBinding.setType( binding.getType() );
}
protected void errorOrLogForPaginationWithCollectionFetch() {
if ( getSessionFactory().getSessionFactoryOptions()
.isFailOnPaginationOverCollectionFetchEnabled() ) {
throw new HibernateException(
"setFirstResult() or setMaxResults() specified with collection fetch join "
+ "(in-memory pagination was about to be applied, but '"
+ FAIL_ON_PAGINATION_OVER_COLLECTION_FETCH
+ "' is enabled)"
);
}
else {
QUERY_MESSAGE_LOGGER.firstOrMaxResultsSpecifiedWithCollectionFetch();
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Utilities
protected int getIntegerLiteral(JpaExpression<Number> expression) {
if ( expression == null ) {
return 0;View on GitHub (pinned to fad1729dce)
Solutions
- Pagination combined with a collection fetch join would be applied in memory, and fail_on_pagination_over_collection_fetch is enabled. Remove the collection fetch join, drop pagination, or set hibernate.query.fail_on_pagination_over_collection_fetch=false.
When it happens
Trigger: Key-based pagination preconditions are not met: setFirstResult() or setMaxResults() specified with collection fetch join (in-memory pagination was about to be applied, but 'hibernate.query.fail_on_pagination_over_collection_fetch' is enabled)
Common situations: Using key-based pagination on queries with no/multiple roots, multi-item select lists, non-entity select items, or pages containing null key values.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b5a2c6a30d9e2475.
Report an issue: GitHub.