{"record":{"id":"d9aa7fe9b559b09e","repo":"hibernate/hibernate-orm","slug":"a-virtual-id-cannot-define-collection-attributes","errorCode":null,"errorMessage":"A \"virtual id\" cannot define collection attributes : {}","messagePattern":"A \"virtual id\" cannot define collection attributes : (.+?)","errorType":"exception","errorClass":"IllegalAttributeType","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java","lineNumber":218,"sourceCode":"\t\t\tComponent bootDescriptor,\n\t\t\tCompositeType compositeType,\n\t\t\tString rootTableExpression,\n\t\t\tString[] rootTableKeyColumnNames,\n\t\t\tMappingModelCreationProcess creationProcess) {\n\n\t\tfinal var attributeMappings = new ImmutableAttributeMappingList.Builder( compositeType.getPropertyNames().length );\n\n\t\treturn finishInitialization(\n\t\t\t\tnavigableRole,\n\t\t\t\tbootDescriptor,\n\t\t\t\tcompositeType,\n\t\t\t\trootTableExpression,\n\t\t\t\trootTableKeyColumnNames,\n\t\t\t\tthis,\n\t\t\t\trepresentationStrategy,\n\t\t\t\t(attributeName, attributeType) -> {\n\t\t\t\t\tif ( attributeType instanceof CollectionType ) {\n\t\t\t\t\t\tthrow new IllegalAttributeType( \"A \\\"virtual id\\\" cannot define collection attributes : \" + attributeName );\n\t\t\t\t\t}\n\t\t\t\t\tif ( attributeType instanceof AnyType ) {\n\t\t\t\t\t\tthrow new IllegalAttributeType( \"A \\\"virtual id\\\" cannot define <any/> attributes : \" + attributeName );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(column, jdbcEnvironment) -> MappingModelCreationHelper.getTableIdentifierExpression( column.getValue().getTable(), creationProcess ),\n\t\t\t\tattributeMappings::add,\n\t\t\t\t() -> {\n\t\t\t\t\tthis.attributeMappings = attributeMappings.build();\n\t\t\t\t\t// We need the attribute mapping types to finish initialization first before we can build the column mappings\n\t\t\t\t\tcreationProcess.registerInitializationCallback(\n\t\t\t\t\t\t\t\"VirtualIdEmbeddable(\" + navigableRole + \")#initColumnMappings\",\n\t\t\t\t\t\t\tthis::initColumnMappings\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tcreationProcess\n\t\t);\n\t}","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdEmbeddable.java#L200-L236","documentation":"Error \"A \"virtual id\" cannot define collection attributes : {}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when an entity whose identifier is a virtual id (mapped from its @IdClass) also declares collection attributes on the id.","commonSituations":"See trigger scenarios.","solutions":["Remove collection attributes from the entity's identifier property; map the identifier with basic or to-one attributes only."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}