hibernate/hibernate-orm · error · IllegalStateException
Duplicate column: " + columnDefinition.name()
Error message
Duplicate column: " + columnDefinition.name()
What it means
The XML counterpart of the json_table guard: SqmXmlTableFunction.Columns.addColumn first calls table.checkTypeResolved() and then rejects any column name already present in columnNames with IllegalStateException('Duplicate column: name'). Every column()/nested()/ordinalityColumn() definition routes through it, so XMLTABLE column names must be unique.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmXmlTableFunction.java:521
// Sanity check
assert offset == componentTypes.length;
return new AnonymousTupleType<>( componentTypes, componentNames );
}
@Override
public Columns copy(SqmCopyContext context) {
final ArrayList<ColumnDefinition> definitions = new ArrayList<>( columnDefinitions.size() );
for ( ColumnDefinition columnDefinition : columnDefinitions ) {
definitions.add( columnDefinition.copy( context ) );
}
return new Columns( castNonNull( context.getCopy( table ) ), definitions );
}
private void addColumn(ColumnDefinition columnDefinition) {
table.checkTypeResolved();
if ( !columnNames.add( columnDefinition.name() ) ) {
throw new IllegalStateException( "Duplicate column: " + columnDefinition.name() );
}
columnDefinitions.add( columnDefinition );
}
@Override
public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
String separator = " columns ";
for ( ColumnDefinition columnDefinition : columnDefinitions ) {
hql.append( separator );
columnDefinition.appendHqlString( hql, context );
separator = ", ";
}
}
@Override
public @Nullable SqmBindableType<Object> getNodeType() {
return null;
}View on GitHub (pinned to fad1729dce)
Solutions
- De-duplicate column names before building the xml_table node.
- Rename the colliding column - the output name and the XPath are independent, so alias one of them.
- Fail fast in builder code with your own duplicate check for a clearer error location.
Example fix
// before t.ordinalityColumn( "node" ); // "node" already defined by a path column -> Duplicate column: node // after t.ordinalityColumn( "node_ord" );
Defensive patterns
Strategy: validation
Validate before calling
Set<String> usedColumnNames = new HashSet<>();
void addXmlTableColumn(String name, Runnable definer) {
if ( !usedColumnNames.add( name ) ) {
throw new IllegalArgumentException( "xml_table column already defined: " + name );
}
definer.run();
} Prevention
- Track xml_table column names in a Set and fail fast on duplicates.
- Uniquify names generated from XPath keys.
- De-duplicate merged column definitions before building the node.
When it happens
Trigger: Defining two columns with the same name on an xml_table criteria node - e.g. an ordinality column colliding with a path column, two path columns sharing one name, or nested column names colliding with top-level ones.
Common situations: Generated column lists from XPath maps with duplicate keys; merging XMLTABLE definitions from several sources; renames that produce a collision.
Related errors
- Duplicate column: {}
- Same column is added more than once with different values fo
- Same column is added more than once with different values fo
- Column '{}' is duplicated in mapping for {} (use '@Column(in
- Could not resolve entity class '{}'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/4ca4b9659af28eb0.
Report an issue: GitHub.