{"record":{"id":"30f7952685610425","repo":"hibernate/hibernate-orm","slug":"key-function-on-non-map","errorCode":"KEY_FUNCTION_ON_NON_MAP","errorMessage":"Strict JPA query language compliance was violated: use of key() function for non-Map type","messagePattern":"Strict JPA query language compliance was violated: use of key\\(\\) function for non-Map type","errorType":"exception","errorClass":"StrictJpaComplianceViolation","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":6074,"sourceCode":"\t\t\t\t&& referencedPathSource instanceof AnonymousTupleType<?> tupleType ) {\n\t\t\tif ( tupleType.findSubPathSource( CollectionPart.Nature.INDEX.getName() ) == null ) {\n\t\t\t\tthrow new FunctionArgumentException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\t\"The set-returning from node '%s' does not specify an index/ordinality\",\n\t\t\t\t\t\t\t\tsqmPath.getNavigablePath()\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tcheckPluralPath( sqmPath, referencedPathSource, firstNode );\n\t\t}\n\n\t\tif ( getCreationOptions().useStrictJpaCompliance() ) {\n\t\t\tfinal var attribute = (PluralPersistentAttribute<?, ?, ?>) referencedPathSource;\n\t\t\tif ( attribute.getCollectionClassification() != CollectionClassification.MAP\n\t\t\t\t\t&& firstNode.getSymbol().getType() == HqlParser.KEY ) {\n\t\t\t\tthrow new StrictJpaComplianceViolation( StrictJpaComplianceViolation.Type.KEY_FUNCTION_ON_NON_MAP );\n\t\t\t}\n\t\t}\n\n\t\tSqmPath<?> result;\n\t\tif ( sqmPath instanceof SqmMapJoin<?, ?, ?> sqmMapJoin ) {\n\t\t\tif ( consumer instanceof QualifiedJoinPathConsumer pathConsumer ) {\n\t\t\t\tif ( madeNested && !hasContinuation ) {\n\t\t\t\t\t// Reset the nested state before consuming the terminal identifier\n\t\t\t\t\tpathConsumer.setNested( false );\n\t\t\t\t}\n\t\t\t\tconsumer.consumeIdentifier( CollectionPart.Nature.INDEX.getName(), false, !hasContinuation );\n\t\t\t\tresult = (SqmPath<?>) consumer.getConsumedPart();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tresult = sqmMapJoin.key();\n\t\t\t}\n\t\t}\n\t\telse if ( sqmPath instanceof SqmListJoin<?, ?> listJoin ) {","sourceCodeStart":6056,"sourceCodeEnd":6092,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L6056-L6092","documentation":"Error \"Strict JPA query language compliance was violated: use of key() function for non-Map type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An HQL-specific construct is used while strict JPQL compliance is enabled: Strict JPA query language compliance was violated: use of key() function for non-Map type","commonSituations":"Applications running with hibernate.jpa.compliance.query=true (or JPA-compliance mode) that submit queries using Hibernate extensions such as collations, tuples/row value constructors, HQL collection functions (maxelement/elements/indices), value()/key() on non-Map types, or non-standard function calls without FUNCTION() syntax.","solutions":["key() is only valid for Map associations. Apply key() to a map-valued path, or relax strict JPA compliance if appropriate."],"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"}