hibernate/hibernate-orm · error · IllegalAttributeType

An IdClass cannot define collection attributes : %s

Error message

An IdClass cannot define collection attributes : %s

What it means

Error "An IdClass cannot define collection attributes : %s" thrown in hibernate/hibernate-orm.

Source

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

	private boolean finishInitialization(
			Component bootDescriptor,
			CompositeType compositeType,
			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)

Solutions

  1. Remove collection-typed attributes from the @IdClass; an IdClass may only contain basic id attributes matching the entity's identifiers.

When it happens

Trigger: Thrown when an @IdClass class declares a collection attribute; IdClass classes may only contain simple id attributes.

Common situations: See trigger scenarios.


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