{"record":{"id":"d7c8844263ec73fa","repo":"hibernate/hibernate-orm","slug":"column-attribute-and-formula-attribute-may-not-be","errorCode":null,"errorMessage":"column attribute and formula attribute may not be specified together near <%s name=\"%s\" column=\"%s\" formula=\"%s\" />","messagePattern":"column attribute and formula attribute may not be specified together near <(.+?) name=\"(.+?)\" column=\"(.+?)\" formula=\"(.+?)\" />","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java","lineNumber":372,"sourceCode":"\t\t\t\terrorMessage = String.format(\n\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\"column attribute and formula attribute may not be specified together near <%s name=\\\"%s\\\" column=\\\"%s\\\" formula=\\\"%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\t\tcolumnsAndFormulasSource.getFormulaAttribute()\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 and formula attribute may not be specified together near <%s column=\\\"%s\\\" formula=\\\"%s\\\" />\",\n\t\t\t\t\t\tcolumnsAndFormulasSource.getSourceType().getElementName(),\n\t\t\t\t\t\tcolumnsAndFormulasSource.getColumnAttribute(),\n\t\t\t\t\t\tcolumnsAndFormulasSource.getFormulaAttribute()\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new MappingException( errorMessage, sourceDocument.getOrigin() );\n\t\t}\n\t\t//\t\t2) and no column/formula nested elements\n\t\tif ( isNotEmpty( columnsAndFormulasSource.getColumnOrFormulaElements() ) ) {\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\"formula attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\\\"%s\\\" formula=\\\"%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.getFormulaAttribute()\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\"formula attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s formula=\\\"%s\\\" />\",","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java#L354-L390","documentation":"An hbm mapping element may describe its relational value either through the column='...' attribute or through the formula='...' attribute, but never both at once. During value-source validation Hibernate detects both attributes set on the same element and throws, interpolating the element name, its name attribute, and both attribute values so the exact spot is identifiable.","triggerScenarios":"Any mapping element carrying both attributes simultaneously, e.g. <property name='total' column='total_col' formula='(select sum(x) from t)'/> or <key column='id' formula='...'/>.","commonSituations":"Adding a formula to an existing column-mapped element without removing the column attribute; merging attributes while copy-pasting elements; templates that pre-fill every attribute.","solutions":["Delete one of the two attributes - keep column='...' for a physical column or formula='...' for a derived value","If both the stored column and a derived view of it are needed, map two separate properties","Grep mapping files for elements carrying both column= and formula= to catch other occurrences"],"exampleFix":"// before\n<property name='total' column='total_col' formula='(select sum(amount) from lines)'/>\n\n// after\n<property name='total' formula='(select sum(amount) from lines)'/>","handlingStrategy":"validation","validationCode":"// Pre-flight: no element may carry both column= and formula= attributes\nvar elements = doc.getElementsByTagName(\"*\"); // walk all mapped elements\nfor (int i = 0; i < elements.getLength(); i++) {\n    var e = (org.w3c.dom.Element) elements.item(i);\n    if (!e.getAttribute(\"column\").isEmpty() && !e.getAttribute(\"formula\").isEmpty())\n        throw new IllegalStateException(\"<\" + e.getTagName() + \" name='\" + e.getAttribute(\"name\")\n                + \"'> sets both column and formula\");\n}","typeGuard":null,"tryCatchPattern":"catch (org.hibernate.boot.MappingException e) at Metadata build: the message prints element name and both attribute values - delete one of the two attributes on that element","preventionTips":["Pick one style per element (attribute vs nested) and stick to it","When adding a formula to an existing mapping, remove the column attribute in the same edit","Grep mapping files for column=.*formula= patterns in CI"],"tags":["hibernate","hbm","mapping","attributes","orm"],"backgroundTag":"mutually-exclusive-attributes","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}