{"record":{"id":"c1a6a7fec503ac51","repo":"hibernate/hibernate-orm","slug":"column-is-duplicated-in-mapping-for-use","errorCode":null,"errorMessage":"Column '{}' is duplicated in mapping for {} (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)","messagePattern":"Column '(.+?)' is duplicated in mapping for (.+?) \\(use '@Column\\(insertable=false, updatable=false\\)' when mapping multiple properties to the same column\\)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/Value.java","lineNumber":224,"sourceCode":"\t\t\tif ( getSelectables().get( i ) instanceof Column column\n\t\t\t\t\t&& ( isColumnInsertable( i ) || isColumnUpdateable( i ) ) ) {\n\t\t\t\tfinal var primaryTable = getTable();\n\t\t\t\tfinal Identifier catalog;\n\t\t\t\tfinal Identifier schema;\n\t\t\t\tfinal Identifier table;\n\t\t\t\tif ( primaryTable != null ) {\n\t\t\t\t\tcatalog = primaryTable.getCatalogIdentifier();\n\t\t\t\t\tschema = primaryTable.getSchemaIdentifier();\n\t\t\t\t\ttable = primaryTable.getNameIdentifier();\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tcatalog = null;\n\t\t\t\t\tschema = null;\n\t\t\t\t\ttable = null;\n\t\t\t\t}\n\t\t\t\tfinal var columnName = column.getNameIdentifier( getBuildingContext() );\n\t\t\t\tif ( !distinctColumns.add( new QualifiedColumnName( catalog, schema, table, columnName ) ) ){\n\t\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\t\"Column '\" + column.getName()\n\t\t\t\t\t\t\t\t\t+ \"' is duplicated in mapping for \" + owner\n\t\t\t\t\t\t\t\t\t+ \" (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":206,"sourceCodeEnd":234,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/Value.java#L206-L234","documentation":"During Value validation, Hibernate collects the qualified column names an entity maps and throws when the same (catalog, schema, table, column) is claimed twice by properties of one owner. Mapping the same column to two writable properties is ambiguous for inserts/updates, so the message tells you to mark one side read-only with @Column(insertable=false, updatable=false).","triggerScenarios":"An entity mapping both an association (@ManyToOne with @JoinColumn) and a plain property to the same FK column; a shared natural key mapped on two fields; overriding @AttributeOverrides that point two embeddable fields at one column; a component/embeddable re-declaring a column already mapped on the owning entity.","commonSituations":"Classic derived-identity pattern done wrong (id field plus @ManyToOne on the same PK column instead of @MapsId); legacy HBM annotations migrations where both FK field and object association were kept writable; embeddables reused in the same entity twice without distinct column overrides; @ManyToOne + @Column pair for the same join column.","solutions":["Make one of the two mappings read-only: @Column(name = \"customer_id\", insertable = false, updatable = false).","For primary-key sharing use @MapsId on the association instead of a duplicated @Id column (or @JoinColumn + @Id legacy style with correct flags).","Give embeddable properties distinct columns via @AttributeOverride(name = \"...\", column = @Column(name = \"...\")).","Rename the column on one property if the duplication was unintentional."],"exampleFix":"// before\n@Id\n@Column(name = \"customer_id\")\nprivate Long customerId;\n\n@ManyToOne\n@JoinColumn(name = \"customer_id\")\nprivate Customer customer; // duplicate writable column\n\n// after\n@ManyToOne(fetch = FetchType.LAZY)\n@MapsId\nprivate Customer customer;","handlingStrategy":"validation","validationCode":"// build metadata eagerly so duplicate column mapping surfaces at startup with entity name\nMetadata md = sources.getMetadataBuilder().build();\nmd.buildMetadata().validate(); // MappingException names the column and the owner","typeGuard":null,"tryCatchPattern":"try {\n    sf = cfg.buildSessionFactory();\n} catch (MappingException e) {\n    if (e.getMessage().startsWith(\"Column '\") && e.getMessage().contains(\"is duplicated in mapping\")) {\n        // parse column + entity from message; mark one mapping insertable=false/updatable=false or use @MapsId\n    }\n    throw e;\n}","preventionTips":["For derived identities use @MapsId instead of duplicating the FK column.","When keeping both a FK field and an association, mark the field @Column(insertable=false, updatable=false).","Give embeddables explicit @AttributeOverride column names when reusing embeddables in one entity."],"tags":["hibernate","duplicate-column","orm-mapping","join-column","mapsid"],"backgroundTag":"duplicate-column-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}