{"record":{"id":"32adea44e2a742fe","repo":"hibernate/hibernate-orm","slug":"hql-collection-function","errorCode":"HQL_COLLECTION_FUNCTION","errorMessage":"Strict JPA query language compliance was violated: use of HQL collection functions (maxelement, minelement, maxindex, minindex, elements, indices)","messagePattern":"Strict JPA query language compliance was violated: use of HQL collection functions \\(maxelement, minelement, maxindex, minindex, elements, indices\\)","errorType":"exception","errorClass":"StrictJpaComplianceViolation","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":1489,"sourceCode":"\t\tif ( expressionOrPredicate.expression()\n\t\t\t\t\tinstanceof HqlParser.BarePrimaryExpressionContext barePrimaryExpression\n\t\t\t\t&& barePrimaryExpression.primaryExpression()\n\t\t\t\t\t\tinstanceof HqlParser.FunctionExpressionContext functionExpression\n\t\t\t\t&& functionExpression.pathContinuation() == null\n\t\t\t\t&& functionExpression.slicedPathAccessFragment() == null\n\t\t\t\t&& functionExpression.indexedPathAccessFragment() == null ) {\n\t\t\tfinal var collectionFunctionMisuse = functionExpression.function().collectionFunctionMisuse();\n\t\t\tif ( collectionFunctionMisuse != null ) {\n\t\t\t\treturn visitCollectionFunctionSelection( collectionFunctionMisuse );\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate SqmPluralPartSelectionPath<?> visitCollectionFunctionSelection(\n\t\t\tHqlParser.CollectionFunctionMisuseContext ctx) {\n\t\tif ( getCreationOptions().useStrictJpaCompliance() ) {\n\t\t\tthrow new StrictJpaComplianceViolation( StrictJpaComplianceViolation.Type.HQL_COLLECTION_FUNCTION );\n\t\t}\n\n\t\tfinal var pluralAttributePath = consumeDomainPath( ctx.path() );\n\t\tfinal var firstNode = (TerminalNode) ctx.getChild( 0 ).getChild( 0 );\n\n\t\tif ( !( pluralAttributePath.getReferencedPathSource() instanceof PluralPersistentAttribute<?, ?, ?> ) ) {\n\t\t\tthrow new FunctionArgumentException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\"Argument '%s' of '%s()' function is not a plural path \",\n\t\t\t\t\t\t\tpluralAttributePath.getNavigablePath(),\n\t\t\t\t\t\t\tfirstNode.getSymbol().getText()\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn new SqmPluralPartSelectionPath<>(\n\t\t\t\t(SqmPluralValuedSimplePath<?>) pluralAttributePath,\n\t\t\t\tcollectionFunctionNature( firstNode )","sourceCodeStart":1471,"sourceCodeEnd":1507,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L1471-L1507","documentation":"Error \"Strict JPA query language compliance was violated: use of HQL collection functions (maxelement, minelement, maxindex, minindex, elements, indices)\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An HQL extension is used while strict JPQL compliance is enabled.","commonSituations":"Running HQL-specific syntax (CTEs, limit/offset, collection functions) with hibernate.jpa.compliance.query=true.","solutions":["Disable strict JPA compliance to use HQL collection functions.","Rewrite using standard JPA constructs (joins/subqueries)."],"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"}