hibernate/hibernate-orm · error · IllegalAttributeType
A "virtual id" cannot define collection attributes : {}
Error message
A "virtual id" cannot define collection attributes : {} What it means
Error "A "virtual id" cannot define collection attributes : {}" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java:218
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( "A \"virtual id\" cannot define collection attributes : " + attributeName );
}
if ( attributeType instanceof AnyType ) {
throw new IllegalAttributeType( "A \"virtual id\" cannot define <any/> attributes : " + attributeName );
}
},
(column, jdbcEnvironment) -> MappingModelCreationHelper.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(
"VirtualIdEmbeddable(" + navigableRole + ")#initColumnMappings",
this::initColumnMappings
);
},
creationProcess
);
}View on GitHub (pinned to fad1729dce)
Solutions
- Remove collection attributes from the entity's identifier property; map the identifier with basic or to-one attributes only.
When it happens
Trigger: Thrown when an entity whose identifier is a virtual id (mapped from its @IdClass) also declares collection attributes on the id.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/d9aa7fe9b559b09e.
Report an issue: GitHub.