{"record":{"id":"616268b6fb12f50c","repo":"hibernate/hibernate-orm","slug":"column-attribute-may-not-be-specified-along-with","errorCode":null,"errorMessage":"column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\"%s\" column=\"%s\" />","messagePattern":"column attribute may not be specified along with <column/> or <formula/> subelement\\(s\\) near <(.+?) name=\"(.+?)\" column=\"(.+?)\" />","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java","lineNumber":422,"sourceCode":"\t\t\tif ( columnsAndFormulasSource.getSourceType().canBeNamed()\n\t\t\t\t\t&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {\n\t\t\t\terrorMessage = String.format(\n\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\"column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\\\"%s\\\" column=\\\"%s\\\" />\",\n\t\t\t\t\t\tcolumnsAndFormulasSource.getSourceType().getElementName(),\n\t\t\t\t\t\tcolumnsAndFormulasSource.getSourceName(),\n\t\t\t\t\t\tcolumnsAndFormulasSource.getColumnAttribute()\n\t\t\t\t);\n\t\t\t}\n\t\t\telse {\n\t\t\t\terrorMessage = String.format(\n\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\"column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s column=\\\"%s\\\" />\",\n\t\t\t\t\t\tcolumnsAndFormulasSource.getSourceType().getElementName(),\n\t\t\t\t\t\tcolumnsAndFormulasSource.getColumnAttribute()\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new MappingException( errorMessage, sourceDocument.getOrigin() );\n\t\t}\n\t}\n\n\tprivate static void validateCustomWriteFragment(\n\t\t\tMappingDocument sourceDocument,\n\t\t\tColumnsAndFormulasSource columnsAndFormulasSource,\n\t\t\tJaxbHbmColumnType columnMapping,\n\t\t\tString customWrite) {\n\t\tif ( customWrite != null && !customWrite.matches(\"[^?]*\\\\?[^?]*\") ) {\n\t\t\tfinal String errorMessage;\n\t\t\tif ( columnsAndFormulasSource.getSourceType().canBeNamed()\n\t\t\t\t\t&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {\n\t\t\t\terrorMessage = String.format(\n\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\"write expression must contain exactly one value placeholder ('?') character near <column name=\\\"%s\\\" ... write=\\\"%s\\\" /> for <%s name=\\\"%s\\\" />\",\n\t\t\t\t\t\tcolumnMapping.getName(),\n\t\t\t\t\t\tcustomWrite,\n\t\t\t\t\t\tcolumnsAndFormulasSource.getSourceType().getElementName(),","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java#L404-L440","documentation":"The column='...' attribute and nested <column/>/<formula/> elements are mutually exclusive ways to declare a mapping's relational value. This variant fires when the column attribute is set and nested column/formula children are also present; the message names the element, its name attribute and the column value.","triggerScenarios":"An element such as <many-to-one name='a' column='a_id'> that also contains a nested <column name='a_fk'/> (or <formula/>) child.","commonSituations":"Adding detailed column configuration as a nested element without removing the shorthand attribute; merging mappings; templates pre-filling column= on every element.","solutions":["Remove the column='...' attribute or remove every nested <column/>/<formula/> child - keep exactly one form","Use the nested <column/> form when you need extra column settings (not-null, length, sql-type) and drop the attribute"],"exampleFix":"// before\n<many-to-one name='address' column='addr_id'>\n    <column name='address_fk'/>\n</many-to-one>\n\n// after\n<many-to-one name='address'>\n    <column name='address_fk' not-null='true'/>\n</many-to-one>","handlingStrategy":"validation","validationCode":"// Pre-flight: column attribute must not coexist with nested <column/>/<formula/> children\nvar elements = doc.getElementsByTagName(\"*\");\nfor (int i = 0; i < elements.getLength(); i++) {\n    var e = (org.w3c.dom.Element) elements.item(i);\n    boolean nested = e.getElementsByTagName(\"column\").getLength() > 0\n            || e.getElementsByTagName(\"formula\").getLength() > 0;\n    if (!e.getAttribute(\"column\").isEmpty() && nested)\n        throw new IllegalStateException(\"<\" + e.getTagName() + \"> mixes column attribute with nested column/formula\");\n}","typeGuard":null,"tryCatchPattern":"catch (org.hibernate.boot.MappingException e) at Metadata build: the message names the element, its name and the column value - drop the attribute or the nested children","preventionTips":["When adding nested <column> details, remove the shorthand column= attribute","Prefer nested <column/> exclusively once column options (not-null, length, sql-type) are needed","Lint mapping files for attribute-plus-children combos in CI"],"tags":["hibernate","hbm","mapping","attributes","columns","orm"],"backgroundTag":"mutually-exclusive-attributes","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}