hibernate/hibernate-orm · error · UnsupportedMappingException

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

Error message

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

What it means

Error "Only the key and discriminator parts of an '@Any' mapping may be dereferenced" thrown in hibernate/hibernate-orm.

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)

Solutions

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

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.