hibernate/hibernate-orm · error · UnsupportedMappingException

Only the key and discriminator parts of an '@Any' mapping…

Error message

Only the key and discriminator parts of an '@Any' mapping may be dereferenced

What it means

Path-source guard for @Any mappings: findSubPathSource was called with a name other than 'key'/'id' or 'discriminator'/'class', but only those parts of an @Any mapping can be dereferenced in a path.

Solutions

  1. In the query, dereference only the key or discriminator part of the @Any mapping; load the target entity separately for further navigation.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown when a query path dereferences a part of an @Any mapping other than its key or discriminator.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java:63

		);
	}

	@Override
	public @Nullable SqmPathSource<?> findSubPathSource(String name) {
		return switch ( name ) {
			case AnyKeyPart.KEY_NAME ->
				// standard id() function
					keyPathSource;
			case AnyDiscriminatorPart.ROLE_NAME ->
				// standard type() function
					discriminatorPathSource;
			case "id" ->
				// deprecated HQL .id syntax
					keyPathSource;
			case "class" ->
				// deprecated HQL .class syntax
					discriminatorPathSource;
			default -> throw new UnsupportedMappingException(
					"Only the key and discriminator parts of an '@Any' mapping may be dereferenced" );
		};
	}

	@Override
	public SqmPath<J> createSqmPath(SqmPath<?> lhs, @Nullable SqmPathSource<?> intermediatePathSource) {
		return new SqmAnyValuedSimplePath<>(
				PathHelper.append( lhs, this, intermediatePathSource ),
				pathModel,
				lhs,
				lhs.nodeBuilder()
		);
	}
}

View on GitHub (pinned to fad1729dce)