{"record":{"id":"8d4354146f36fe3f","repo":"hibernate/hibernate-orm","slug":"identifier-mapping-has-wrong-number-of-columns","errorCode":null,"errorMessage":"identifier mapping has wrong number of columns: \" + getEntityName() + \" type: \" + getIdentifier().getType().getName()","messagePattern":"identifier mapping has wrong number of columns: \" \\+ getEntityName\\(\\) \\+ \" type: \" \\+ getIdentifier\\(\\)\\.getType\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java","lineNumber":281,"sourceCode":"\n\tpublic void setConcreteProxy(boolean concreteProxy) {\n\t\tthis.concreteProxy = concreteProxy;\n\t}\n\n\t@Override\n\tpublic String getWhere() {\n\t\treturn where;\n\t}\n\n\tpublic void setWhere(String string) {\n\t\twhere = string;\n\t}\n\n\t@Override\n\tpublic void validate(Metadata mapping) throws MappingException {\n\t\tsuper.validate( mapping );\n\t\tif ( !getIdentifier().isValid( mapping ) ) {\n\t\t\tthrow new MappingException(\n\t\t\t\t\t\"identifier mapping has wrong number of columns: \" +\n\t\t\t\t\t\t\tgetEntityName() +\n\t\t\t\t\t\t\t\" type: \" +\n\t\t\t\t\t\t\tgetIdentifier().getType().getName()\n\t\t\t);\n\t\t}\n\t\tcheckCompositeIdentifier();\n\t\tcheckTableDuplication();\n\t}\n\n\t/**\n\t * In {@linkplain jakarta.persistence.InheritanceType#SINGLE_TABLE single table}\n\t * inheritance, subclasses share a table with the root class by definition. But\n\t * for {@linkplain jakarta.persistence.InheritanceType#JOINED joined} or\n\t * {@linkplain jakarta.persistence.InheritanceType#TABLE_PER_CLASS union} mappings,\n\t * the subclasses are assumed to occupy distinct tables, and it's an error to map\n\t * two subclasses to the same table.\n\t * <p>","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java#L263-L299","documentation":"Root-class validation found the identifier mapping invalid: getIdentifier().isValid(mapping) returned false for the id Value of a root entity. Like the column-span check for normal properties, but specific to the identifier: the id type's required column count disagrees with the mapped columns, or the id Value is otherwise invalid.","triggerScenarios":"An @EmbeddedId whose component columns do not match the embeddable's properties; an id assigned a custom type spanning multiple columns while only one column is mapped; hbm composite-id with key-property lists that do not align; formulas used inside the identifier.","commonSituations":"Changing an id from simple to composite (or back) without updating columns; legacy hbm composite ids after a schema change; custom UserType identifiers after a Hibernate upgrade.","solutions":["For composite ids, map exactly one column per key property (one @EmbeddedId field per column, or one key-property entry per column in hbm)","Verify the id type's column span matches the mapped column count","Avoid formulas in identifiers; map real columns instead"],"exampleFix":"// before\n<composite-id class=\"OrderId\">\n  <key-property name=\"tenantId\"/>\n  <key-property name=\"seq\"/>  <!-- OrderId maps only tenantId to a column -->\n</composite-id>\n\n// after\n<!-- make OrderId map both tenantId and seq to real columns -->","handlingStrategy":"validation","validationCode":"for (PersistentClass pc : metadata.getEntityBindings()) {\n    if (pc instanceof RootClass root && !root.getIdentifier().isValid((Mapping) metadata)) {\n        // identifier column count mismatch; fix the id mapping before bootstrap\n    }\n}","typeGuard":null,"tryCatchPattern":"try { metadata.buildSessionFactory(); }\ncatch (MappingException e) {\n    if (e.getMessage().contains(\"identifier mapping has wrong number of columns\")) {\n        // align the composite id components with the mapped columns\n    }\n    throw e;\n}","preventionTips":["Keep composite id classes in sync with the physical key columns via tests","Avoid formulas and computed values inside identifiers","Re-validate id mappings after changing key types or column lists"],"tags":["hibernate","orm","mapping-validation","identifier","composite-key"],"backgroundTag":"column-count-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}