hibernate/hibernate-orm · error · StrictJpaComplianceViolation

KEY_FUNCTION_ON_NON_MAP

KEY_FUNCTION_ON_NON_MAP

Error message

Strict JPA query language compliance was violated: use of key() function for non-Map type

What it means

Error "Strict JPA query language compliance was violated: use of key() function for non-Map type" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:6074

				&& referencedPathSource instanceof AnonymousTupleType<?> tupleType ) {
			if ( tupleType.findSubPathSource( CollectionPart.Nature.INDEX.getName() ) == null ) {
				throw new FunctionArgumentException(
						String.format(
								"The set-returning from node '%s' does not specify an index/ordinality",
								sqmPath.getNavigablePath()
						)
				);
			}
		}
		else {
			checkPluralPath( sqmPath, referencedPathSource, firstNode );
		}

		if ( getCreationOptions().useStrictJpaCompliance() ) {
			final var attribute = (PluralPersistentAttribute<?, ?, ?>) referencedPathSource;
			if ( attribute.getCollectionClassification() != CollectionClassification.MAP
					&& firstNode.getSymbol().getType() == HqlParser.KEY ) {
				throw new StrictJpaComplianceViolation( StrictJpaComplianceViolation.Type.KEY_FUNCTION_ON_NON_MAP );
			}
		}

		SqmPath<?> result;
		if ( sqmPath instanceof SqmMapJoin<?, ?, ?> sqmMapJoin ) {
			if ( consumer instanceof QualifiedJoinPathConsumer pathConsumer ) {
				if ( madeNested && !hasContinuation ) {
					// Reset the nested state before consuming the terminal identifier
					pathConsumer.setNested( false );
				}
				consumer.consumeIdentifier( CollectionPart.Nature.INDEX.getName(), false, !hasContinuation );
				result = (SqmPath<?>) consumer.getConsumedPart();
			}
			else {
				result = sqmMapJoin.key();
			}
		}
		else if ( sqmPath instanceof SqmListJoin<?, ?> listJoin ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. key() is only valid for Map associations. Apply key() to a map-valued path, or relax strict JPA compliance if appropriate.

When it happens

Trigger: 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

Common situations: 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.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/30f7952685610425. Report an issue: GitHub.