hibernate/hibernate-orm · error · MappingException
Column '{}' is duplicated in mapping for {} (use '@Column(in
Error message
Column '{}' is duplicated in mapping for {} (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column) What it means
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).
Source
Thrown at hibernate-core/src/main/java/org/hibernate/mapping/Value.java:224
if ( getSelectables().get( i ) instanceof Column column
&& ( isColumnInsertable( i ) || isColumnUpdateable( i ) ) ) {
final var primaryTable = getTable();
final Identifier catalog;
final Identifier schema;
final Identifier table;
if ( primaryTable != null ) {
catalog = primaryTable.getCatalogIdentifier();
schema = primaryTable.getSchemaIdentifier();
table = primaryTable.getNameIdentifier();
}
else {
catalog = null;
schema = null;
table = null;
}
final var columnName = column.getNameIdentifier( getBuildingContext() );
if ( !distinctColumns.add( new QualifiedColumnName( catalog, schema, table, columnName ) ) ){
throw new MappingException(
"Column '" + column.getName()
+ "' is duplicated in mapping for " + owner
+ " (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)"
);
}
}
}
}
}
View on GitHub (pinned to fad1729dce)
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.
Example fix
// before @Id @Column(name = "customer_id") private Long customerId; @ManyToOne @JoinColumn(name = "customer_id") private Customer customer; // duplicate writable column // after @ManyToOne(fetch = FetchType.LAZY) @MapsId private Customer customer;
Defensive patterns
Strategy: validation
Validate before calling
// build metadata eagerly so duplicate column mapping surfaces at startup with entity name Metadata md = sources.getMetadataBuilder().build(); md.buildMetadata().validate(); // MappingException names the column and the owner
Try / catch
try {
sf = cfg.buildSessionFactory();
} catch (MappingException e) {
if (e.getMessage().startsWith("Column '") && e.getMessage().contains("is duplicated in mapping")) {
// parse column + entity from message; mark one mapping insertable=false/updatable=false or use @MapsId
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Association '{}' in entity '{}' is annotated '@MapsId' but r
- Identifier field '{}' named in '@MapsId' does not exist in e
- A '@JoinColumn' references a column named '{}' but the targe
- No column with logical name '{}' in table '{}'
- Class '<componentClassName>' is an '@Embeddable' type and ma
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c1a6a7fec503ac51.
Report an issue: GitHub.