{"record":{"id":"3ea4aab04cb60abc","repo":"hibernate/hibernate-orm","slug":"formula-attribute-may-not-be-specified-along-with","errorCode":null,"errorMessage":"formula attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\"%s\" formula=\"%s\" />","messagePattern":"formula attribute may not be specified along with <column/> or <formula/> subelement\\(s\\) near <(.+?) name=\"(.+?)\" 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":395,"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\"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\\\" />\",\n\t\t\t\t\t\tcolumnsAndFormulasSource.getSourceType().getElementName(),\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}\n\n\tprivate static void validateUseOfColumnOrFormulaNestedElements(\n\t\t\tMappingDocument sourceDocument,\n\t\t\tColumnsAndFormulasSource columnsAndFormulasSource) {\n\t\tif ( isNotEmpty( columnsAndFormulasSource.getColumnAttribute() ) ) {\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\"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}","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java#L377-L413","documentation":"Besides the formula='...' attribute, a mapping element may declare its value with nested <column/> or <formula/> elements - one form at a time. This error fires when the formula attribute is present and the element also contains nested column/formula children; the message interpolates the element name, name attribute and the formula value.","triggerScenarios":"An element such as <property name='x' formula='(select ...)'> that also contains a nested <column name='x_col'/> (or any <formula/>) child.","commonSituations":"Refactoring from nested elements to the attribute shorthand and leaving the children in place; code generation appending children to a template that already sets the attribute; merging two variants of the same mapping.","solutions":["Remove the formula='...' attribute or remove every nested <column/>/<formula/> child - keep exactly one form","Prefer nested <column/> when you need column details (length, sql-type, check constraints); use the attribute only for plain single-value mappings"],"exampleFix":"// before\n<property name='total' formula='(select sum(amount) from lines)'>\n    <column name='total_col'/>\n</property>\n\n// after\n<property name='total' formula='(select sum(amount) from lines)'/>","handlingStrategy":"validation","validationCode":"// Pre-flight: formula 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(\"formula\").isEmpty() && nested)\n        throw new IllegalStateException(\"<\" + e.getTagName() + \"> mixes formula attribute with nested column/formula\");\n}","typeGuard":null,"tryCatchPattern":"catch (org.hibernate.boot.MappingException e) at Metadata build: the message names the element and the formula value - remove either the attribute or the nested children so one form remains","preventionTips":["Use the attribute shorthand only for plain values; switch fully to nested elements when column details are needed","After refactoring mappings, check that no shorthand attribute survived alongside nested children","Run a mapping lint that flags attribute-plus-children combinations"],"tags":["hibernate","hbm","mapping","attributes","formula","orm"],"backgroundTag":"mutually-exclusive-attributes","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}