{"record":{"id":"8934c9659e9d972e","repo":"hibernate/hibernate-orm","slug":"the-jpa-specification-does-not-support-the-fetch-o","errorCode":null,"errorMessage":"The JPA specification does not support the fetch or offset clause. Please disable the JPA query compliance if you want to use this feature.","messagePattern":"The JPA specification does not support the fetch or offset clause\\. Please disable the JPA query compliance if you want to use this feature\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmSelectStatement.java","lineNumber":558,"sourceCode":"\t\treturn this;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic JpaCriteriaQuery<T> fetch(@Nullable Number fetch, FetchClauseType fetchClauseType) {\n\t\tvalidateComplianceFetchOffset();\n\t\tgetQueryPart().setFetch( nodeBuilder().value( fetch ), fetchClauseType );\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic FetchClauseType getFetchClauseType() {\n\t\treturn getQueryPart().getFetchClauseType();\n\t}\n\n\tprivate void validateComplianceFetchOffset() {\n\t\tif ( nodeBuilder().isJpaQueryComplianceEnabled() ) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"The JPA specification does not support the fetch or offset clause. \" +\n\t\t\t\t\t\t\t\"Please disable the JPA query compliance if you want to use this feature.\" );\n\t\t}\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic SqmSelectStatement<Long> createCountQuery() {\n\t\tfinal SqmSelectStatement<Long> copy = createCopy( noParamCopyContext(), Long.class );\n\t\tfinal SqmQueryPart<Long> queryPart = copy.getQueryPart();\n\t\t//TODO: detect queries with no 'group by', but aggregate functions\n\t\t//      in 'select' list (we don't even need to hit the database to\n\t\t//      know they return exactly one row)\n\t\tif ( queryPart instanceof SqmQuerySpec<?> querySpec\n\t\t\t\t&& !querySpec.isDistinct()\n\t\t\t\t&& querySpec.getGroupingExpressions().isEmpty() ) {\n\t\t\t// we can just remove any fetch joins and\n\t\t\t// replace the select list with count(*)","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmSelectStatement.java#L540-L576","documentation":"Error \"The JPA specification does not support the fetch or offset clause. Please disable the JPA query compliance if you want to use this feature.\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A fetch or offset clause is set on a query while JPA query compliance mode is enabled; plain JPA does not support them.","commonSituations":"Using setFirstResult/setMaxResults equivalents or LIMIT/OFFSET extensions; disable JPA compliance or use standard pagination.","solutions":["Disable JPA query compliance to allow the fetch/offset clause.","Use JPA-standard pagination instead: Query#setFirstResult and Query#setMaxResults.","Use HQL or native SQL where the fetch/offset clause is supported."],"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"}