{"record":{"id":"d47aed887875e3d7","repo":"hibernate/hibernate-orm","slug":"expecting-just-a-single-formula-column-in-context","errorCode":null,"errorMessage":"Expecting just a single formula/column in context of <%s name=\"%s\"/>","messagePattern":"Expecting just a single formula/column in context of <(.+?) name=\"(.+?)\"/>","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java","lineNumber":154,"sourceCode":"\t *\n\t * @param mappingDocument the mapping document\n\t * @param containingTableName The logical name of the table containing the relational values\n\t * @param columnsAndFormulasSource the adapter describing the value sources.\n\t *\n\t * @return The single RelationalValueSource.\n\t */\n\tpublic static RelationalValueSource buildValueSource(\n\t\t\tMappingDocument mappingDocument,\n\t\t\tString containingTableName,\n\t\t\tColumnsAndFormulasSource columnsAndFormulasSource) {\n\t\tfinal List<RelationalValueSource> sources = buildValueSources(\n\t\t\t\tmappingDocument,\n\t\t\t\tcontainingTableName,\n\t\t\t\tcolumnsAndFormulasSource\n\t\t);\n\n\t\tif ( sources.size() > 1 ) {\n\t\t\tthrow new MappingException( multipleError( columnsAndFormulasSource ), mappingDocument.getOrigin() );\n\t\t}\n\n\t\treturn sources.get( 0 );\n\t}\n\n\t/**\n\t * Given a {@link ColumnsAndFormulasSource}, build a single {@link RelationalValueSource}\n\t * which is required to be a column.  More than one {@link RelationalValueSource} will result\n\t * in an exception.  A formula, rather than a column, will result in an exception.\n\t *\n\t * @param mappingDocument the mapping document\n\t * @param containingTableName The logical name of the table containing the relational values\n\t * @param columnsAndFormulasSource the adapter describing the value sources.\n\t *\n\t * @return The single ColumnSource.\n\t */\n\tpublic static ColumnSource buildColumnSource(\n\t\t\tMappingDocument mappingDocument,","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java#L136-L172","documentation":"RelationalValueSourceHelper.buildValueSource serves mappings that accept exactly one column or one formula (for example <discriminator/>, <version/>, <timestamp/> style single-valued elements). When the mapping yields more than one RelationalValueSource - two <column> children, or a multi-entry column attribute - bootstrap fails with this message interpolating the element name and its name attribute.","triggerScenarios":"A single-valued mapping element lists multiple relational values, e.g. <discriminator> with two <column> children, or a comma-separated column='a,b' style attribute expanding to two values on an element handled by buildValueSource.","commonSituations":"Attempting a composite discriminator (not supported); splitting one logical column into two <column> halves; mappings carried over from tools that emit multiple column elements for every value.","solutions":["Reduce the element named in the message to exactly one <column> or one <formula>","If the value genuinely spans several columns, this element cannot map it - restructure as a composite (<component>/<properties>) mapping","Check for accidental duplicate <column> children introduced by copy-paste or code generation"],"exampleFix":"// before\n<discriminator>\n    <column name='dtype_a'/>\n    <column name='dtype_b'/>\n</discriminator>\n\n// after\n<discriminator column='dtype'/>","handlingStrategy":"validation","validationCode":"// Pre-flight: single-valued elements (<discriminator>, <version>, <timestamp>, <collection-id>) accept at most one column/formula\nfor (String tag : new String[]{\"discriminator\", \"version\", \"timestamp\", \"collection-id\"}) {\n    var e = (org.w3c.dom.Element) doc.getElementsByTagName(tag).item(0);\n    if (e == null) continue;\n    int n = e.getElementsByTagName(\"column\").getLength() + e.getElementsByTagName(\"formula\").getLength();\n    if (n > 1 || e.getAttribute(\"column\").contains(\",\"))\n        throw new IllegalStateException(tag + \" accepts exactly one column/formula\");\n}","typeGuard":null,"tryCatchPattern":"catch (org.hibernate.boot.MappingException e) at Metadata build: the message names the element and its name attribute - reduce that element to a single <column> or <formula>","preventionTips":["Remember which elements are single-valued (discriminator, version, timestamp, collection-id) and never give them multiple columns","Validate mappings with the hbm XSD and review any element with repeated <column> children","For multi-column data use composite mappings, not single-valued elements"],"tags":["hibernate","hbm","mapping","columns","discriminator","orm"],"backgroundTag":"too-many-mapped-columns","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}