{"record":{"id":"d2802b254c3ea6eb","repo":"hibernate/hibernate-orm","slug":"an-idclass-cannot-define-collection-attributes","errorCode":null,"errorMessage":"An IdClass cannot define collection attributes : %s","messagePattern":"An IdClass cannot define collection attributes : (.+?)","errorType":"exception","errorClass":"IllegalAttributeType","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java","lineNumber":331,"sourceCode":"\tprivate boolean finishInitialization(\n\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\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( \"An IdClass 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( \"An IdClass cannot define <any/> attributes : \" + attributeName );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(column, jdbcEnvironment) -> 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\"IdClassEmbeddable(\" + getNavigableRole() + \")#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":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java#L313-L349","documentation":"Error \"An IdClass cannot define collection attributes : %s\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when an @IdClass class declares a collection attribute; IdClass classes may only contain simple id attributes.","commonSituations":"See trigger scenarios.","solutions":["Remove collection-typed attributes from the @IdClass; an IdClass may only contain basic id attributes matching the entity's identifiers."],"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"}