{"record":{"id":"5213fd3fb76c4b65","repo":"hibernate/hibernate-orm","slug":"scrollable-result-sets-are-not-enabled","errorCode":null,"errorMessage":"Scrollable result sets are not enabled","messagePattern":"Scrollable result sets are not enabled","errorType":"exception","errorClass":"AssertionFailure","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java","lineNumber":142,"sourceCode":"\tpublic PreparedStatement prepareStatement(String sql, final String[] columnNames) {\n\t\tcheckAutoGeneratedKeysSupportEnabled();\n\t\tjdbcCoordinator.executeBatch();\n\t\treturn new StatementPreparationTemplate( sql ) {\n\t\t\tpublic PreparedStatement doPrepare() throws SQLException {\n\t\t\t\treturn connection().prepareStatement( sql, columnNames );\n\t\t\t}\n\t\t}.prepareStatement();\n\t}\n\n\t@Override\n\tpublic PreparedStatement prepareQueryStatement(\n\t\t\tString sql,\n\t\t\tboolean isCallable,\n\t\t\t@Nullable ScrollMode scrollMode) {\n\t\tfinal int resultSetType;\n\t\tif ( scrollMode != null && scrollMode != ScrollMode.FORWARD_ONLY ) {\n\t\t\tif ( !settings().isScrollableResultSetsEnabled() ) {\n\t\t\t\tthrow new AssertionFailure( \"Scrollable result sets are not enabled\" );\n\t\t\t}\n\t\t\tresultSetType = scrollMode.toResultSetType();\n\t\t}\n\t\telse {\n\t\t\tresultSetType = ResultSet.TYPE_FORWARD_ONLY;\n\t\t}\n\n\t\tfinal var preparedStatement =\n\t\t\t\tnew QueryStatementPreparationTemplate( sql ) {\n\t\t\t\t\tpublic PreparedStatement doPrepare() throws SQLException {\n\t\t\t\t\t\treturn isCallable\n\t\t\t\t\t\t\t\t? connection().prepareCall( sql, resultSetType, ResultSet.CONCUR_READ_ONLY )\n\t\t\t\t\t\t\t\t: connection().prepareStatement( sql, resultSetType, ResultSet.CONCUR_READ_ONLY );\n\t\t\t\t\t}\n\t\t\t\t}.prepareStatement();\n\t\tjdbcCoordinator.registerLastQuery( preparedStatement );\n\t\treturn preparedStatement;\n\t}","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java#L124-L160","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: scrolling with the feature disabled\nhibernate.jdbc.use_scrollable_resultset=false\nScrollableResults<?> r = query.scroll(ScrollMode.SCROLL_INSENSITIVE);\n\n// after: paginate without scrollable result sets\nList<?> page = query.setFirstResult(offset).setMaxResults(size).list();","handlingStrategy":"validation","validationCode":"// confirm driver support before relying on scroll()\ntry (Connection c = dataSource.getConnection()) {\n    if (!c.getMetaData().supportsScrollableResults()) {\n        // plan for keyset/offset pagination instead of scroll()\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["configuration","scrollable-results","query","pagination","hibernate"],"backgroundTag":"scrollable-resultset-disabled","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}