{"record":{"id":"4ca4b9659af28eb0","repo":"hibernate/hibernate-orm","slug":"duplicate-column-columndefinition-name","errorCode":null,"errorMessage":"Duplicate column: \" + columnDefinition.name()","messagePattern":"Duplicate column: \" \\+ columnDefinition\\.name\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmXmlTableFunction.java","lineNumber":521,"sourceCode":"\t\t\t// Sanity check\n\t\t\tassert offset == componentTypes.length;\n\n\t\t\treturn new AnonymousTupleType<>( componentTypes, componentNames );\n\t\t}\n\n\t\t@Override\n\t\tpublic Columns copy(SqmCopyContext context) {\n\t\t\tfinal ArrayList<ColumnDefinition> definitions = new ArrayList<>( columnDefinitions.size() );\n\t\t\tfor ( ColumnDefinition columnDefinition : columnDefinitions ) {\n\t\t\t\tdefinitions.add( columnDefinition.copy( context ) );\n\t\t\t}\n\t\t\treturn new Columns( castNonNull( context.getCopy( table ) ), definitions );\n\t\t}\n\n\t\tprivate void addColumn(ColumnDefinition columnDefinition) {\n\t\t\ttable.checkTypeResolved();\n\t\t\tif ( !columnNames.add( columnDefinition.name() ) ) {\n\t\t\t\tthrow new IllegalStateException( \"Duplicate column: \" + columnDefinition.name() );\n\t\t\t}\n\t\t\tcolumnDefinitions.add( columnDefinition );\n\t\t}\n\n\t\t@Override\n\t\tpublic void appendHqlString(StringBuilder hql, SqmRenderContext context) {\n\t\t\tString separator = \" columns \";\n\t\t\tfor ( ColumnDefinition columnDefinition : columnDefinitions ) {\n\t\t\t\thql.append( separator );\n\t\t\t\tcolumnDefinition.appendHqlString( hql, context );\n\t\t\t\tseparator = \", \";\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic @Nullable SqmBindableType<Object> getNodeType() {\n\t\t\treturn null;\n\t\t}","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmXmlTableFunction.java#L503-L539","documentation":"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.","triggerScenarios":"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.","commonSituations":"Generated column lists from XPath maps with duplicate keys; merging XMLTABLE definitions from several sources; renames that produce a collision.","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."],"exampleFix":"// before\nt.ordinalityColumn( \"node\" );  // \"node\" already defined by a path column -> Duplicate column: node\n\n// after\nt.ordinalityColumn( \"node_ord\" );","handlingStrategy":"validation","validationCode":"Set<String> usedColumnNames = new HashSet<>();\n\nvoid addXmlTableColumn(String name, Runnable definer) {\n    if ( !usedColumnNames.add( name ) ) {\n        throw new IllegalArgumentException( \"xml_table column already defined: \" + name );\n    }\n    definer.run();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["hibernate","xml-table","duplicate-column","criteria-api"],"backgroundTag":"duplicate-column-definition","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}