hibernate/hibernate-orm · error · IllegalAttributeType

An IdClass cannot define <any/> attributes

Error message

An IdClass cannot define <any/> attributes : %s

What it means

IdClass mapping validation: the id class declares an <any/>-typed attribute, which is not permitted in an IdClass. The message names the offending attribute.

Solutions

  1. Remove <any/> (or @Any) attributes from the @IdClass; model the identifier with basic attributes or entity references instead.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown when an @IdClass class declares an @Any attribute; any-mappings are not allowed in identifier classes.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java:334

			String rootTableExpression,
			String[] rootTableKeyColumnNames,
			MappingModelCreationProcess creationProcess) {
		final var attributeMappings = new ImmutableAttributeMappingList.Builder( compositeType.getPropertyNames().length );

		return finishInitialization(
				navigableRole,
				bootDescriptor,
				compositeType,
				rootTableExpression,
				rootTableKeyColumnNames,
				this,
				representationStrategy,
				(attributeName, attributeType) -> {
					if ( attributeType instanceof CollectionType ) {
						throw new IllegalAttributeType( "An IdClass cannot define collection attributes : " + attributeName );
					}
					if ( attributeType instanceof AnyType ) {
						throw new IllegalAttributeType( "An IdClass cannot define <any/> attributes : " + attributeName );
					}
				},
				(column, jdbcEnvironment) -> getTableIdentifierExpression( column.getValue().getTable(), creationProcess ),
				attributeMappings::add,
				() -> {
					this.attributeMappings = attributeMappings.build();
					// We need the attribute mapping types to finish initialization first before we can build the column mappings
					creationProcess.registerInitializationCallback(
							"IdClassEmbeddable(" + getNavigableRole() + ")#initColumnMappings",
							this::initColumnMappings
					);
				},
				creationProcess
		);
	}

}

View on GitHub (pinned to fad1729dce)