hibernate/hibernate-orm · error · AssertionFailure
Scrollable result sets are not enabled
Error message
Scrollable result sets are not enabled
What it means
StatementPreparerImpl.prepareQueryStatement throws AssertionFailure('Scrollable result sets are not enabled') when a query requests a ScrollMode other than FORWARD_ONLY but the setting hibernate.jdbc.use_scrollable_resultset resolved to false. The default is auto-detected from DatabaseMetaData.supportsScrollableResults(), so an explicit false (or a driver reporting no support) conflicts with scroll() calls.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java:142
public PreparedStatement prepareStatement(String sql, final String[] columnNames) {
checkAutoGeneratedKeysSupportEnabled();
jdbcCoordinator.executeBatch();
return new StatementPreparationTemplate( sql ) {
public PreparedStatement doPrepare() throws SQLException {
return connection().prepareStatement( sql, columnNames );
}
}.prepareStatement();
}
@Override
public PreparedStatement prepareQueryStatement(
String sql,
boolean isCallable,
@Nullable ScrollMode scrollMode) {
final int resultSetType;
if ( scrollMode != null && scrollMode != ScrollMode.FORWARD_ONLY ) {
if ( !settings().isScrollableResultSetsEnabled() ) {
throw new AssertionFailure( "Scrollable result sets are not enabled" );
}
resultSetType = scrollMode.toResultSetType();
}
else {
resultSetType = ResultSet.TYPE_FORWARD_ONLY;
}
final var preparedStatement =
new QueryStatementPreparationTemplate( sql ) {
public PreparedStatement doPrepare() throws SQLException {
return isCallable
? connection().prepareCall( sql, resultSetType, ResultSet.CONCUR_READ_ONLY )
: connection().prepareStatement( sql, resultSetType, ResultSet.CONCUR_READ_ONLY );
}
}.prepareStatement();
jdbcCoordinator.registerLastQuery( preparedStatement );
return preparedStatement;
}View on GitHub (pinned to fad1729dce)
Solutions
- Remove the explicit hibernate.jdbc.use_scrollable_resultset=false, or set it to true if the driver supports scrollable cursors
- Replace scroll() usage with setFirstResult/setMaxResults pagination, which does not need scrollable result sets
- Verify the driver really supports ResultSet.TYPE_SCROLL_INSENSITIVE before forcing the setting on
Example fix
// before: scrolling with the feature disabled hibernate.jdbc.use_scrollable_resultset=false ScrollableResults<?> r = query.scroll(ScrollMode.SCROLL_INSENSITIVE); // after: paginate without scrollable result sets List<?> page = query.setFirstResult(offset).setMaxResults(size).list();
Defensive patterns
Strategy: validation
Validate before calling
// confirm driver support before relying on scroll()
try (Connection c = dataSource.getConnection()) {
if (!c.getMetaData().supportsScrollableResults()) {
// plan for keyset/offset pagination instead of scroll()
}
} Prevention
- Do not set hibernate.jdbc.use_scrollable_resultset=false while code calls scroll()
- Prefer setFirstResult/setMaxResults or keyset pagination over ScrollableResults
- Auto-detect (omit the setting) unless you have a measured reason
When it happens
Trigger: Query.scroll(ScrollMode.SCROLL_INSENSITIVE) or SCROLL_SENSITIVE (including internal paths like ScrollableResults iteration and some pagination implementations) while hibernate.jdbc.use_scrollable_resultset=false is set, or the driver reported no scrollable-resultset support at metadata extraction.
Common situations: Configs inherited from older tuning guides that set use_scrollable_resultset=false; unusual drivers/DBs (or proxies like p6spy/older MySQL drivers) where supportsScrollableResults() returns false.
Related errors
- Paged queries not supported by {}
- The JPA specification does not support subqueries having a f
- Can't render offset and fetch clause for subquery
- Can't render offset and fetch clause for subquery
- Can't emulate fetch clause type:
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/5213fd3fb76c4b65.
Report an issue: GitHub.