{"record":{"id":"b5a2c6a30d9e2475","repo":"hibernate/hibernate-orm","slug":"setfirstresult-or-setmaxresults-specified-with","errorCode":null,"errorMessage":"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)","messagePattern":"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\\)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java","lineNumber":1507,"sourceCode":"\t\t\t\tparameterBinding.setBindValue( binding.getBindValue(), explicitTemporalPrecision );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tfinal var bindType = binding.getBindType();\n\t\t\tif ( binding.isMultiValued() ) {\n\t\t\t\tparameterBinding.setBindValues( binding.getBindValues(), bindType );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tparameterBinding.setBindValue( binding.getBindValue(), bindType );\n\t\t\t}\n\t\t}\n\t\tparameterBinding.setType( binding.getType() );\n\t}\n\n\tprotected void errorOrLogForPaginationWithCollectionFetch() {\n\t\tif ( getSessionFactory().getSessionFactoryOptions()\n\t\t\t\t.isFailOnPaginationOverCollectionFetchEnabled() ) {\n\t\t\tthrow new HibernateException(\n\t\t\t\t\t\"setFirstResult() or setMaxResults() specified with collection fetch join \"\n\t\t\t\t\t+ \"(in-memory pagination was about to be applied, but '\"\n\t\t\t\t\t+ FAIL_ON_PAGINATION_OVER_COLLECTION_FETCH\n\t\t\t\t\t+ \"' is enabled)\"\n\t\t\t);\n\t\t}\n\t\telse {\n\t\t\tQUERY_MESSAGE_LOGGER.firstOrMaxResultsSpecifiedWithCollectionFetch();\n\t\t}\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Utilities\n\n\tprotected int getIntegerLiteral(JpaExpression<Number> expression) {\n\t\tif ( expression == null ) {\n\t\t\treturn 0;","sourceCodeStart":1489,"sourceCodeEnd":1525,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java#L1489-L1525","documentation":"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.","triggerScenarios":"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)","commonSituations":"Using key-based pagination on queries with no/multiple roots, multi-item select lists, non-entity select items, or pages containing null key values.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}