hibernate/hibernate-orm · error · MappingException

column attribute may not be specified along with <column/> o

Error message

column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name="%s" column="%s" />

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalValueSourceHelper.java:422

			if ( columnsAndFormulasSource.getSourceType().canBeNamed()
					&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
				errorMessage = String.format(
						Locale.ENGLISH,
						"column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s name=\"%s\" column=\"%s\" />",
						columnsAndFormulasSource.getSourceType().getElementName(),
						columnsAndFormulasSource.getSourceName(),
						columnsAndFormulasSource.getColumnAttribute()
				);
			}
			else {
				errorMessage = String.format(
						Locale.ENGLISH,
						"column attribute may not be specified along with <column/> or <formula/> subelement(s) near <%s column=\"%s\" />",
						columnsAndFormulasSource.getSourceType().getElementName(),
						columnsAndFormulasSource.getColumnAttribute()
				);
			}
			throw new MappingException( errorMessage, sourceDocument.getOrigin() );
		}
	}

	private static void validateCustomWriteFragment(
			MappingDocument sourceDocument,
			ColumnsAndFormulasSource columnsAndFormulasSource,
			JaxbHbmColumnType columnMapping,
			String customWrite) {
		if ( customWrite != null && !customWrite.matches("[^?]*\\?[^?]*") ) {
			final String errorMessage;
			if ( columnsAndFormulasSource.getSourceType().canBeNamed()
					&& isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
				errorMessage = String.format(
						Locale.ENGLISH,
						"write expression must contain exactly one value placeholder ('?') character near <column name=\"%s\" ... write=\"%s\" /> for <%s name=\"%s\" />",
						columnMapping.getName(),
						customWrite,
						columnsAndFormulasSource.getSourceType().getElementName(),

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove the column='...' attribute or remove every nested <column/>/<formula/> child - keep exactly one form
  2. Use the nested <column/> form when you need extra column settings (not-null, length, sql-type) and drop the attribute

Example fix

// before
<many-to-one name='address' column='addr_id'>
    <column name='address_fk'/>
</many-to-one>

// after
<many-to-one name='address'>
    <column name='address_fk' not-null='true'/>
</many-to-one>
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: column attribute must not coexist with nested <column/>/<formula/> children
var elements = doc.getElementsByTagName("*");
for (int i = 0; i < elements.getLength(); i++) {
    var e = (org.w3c.dom.Element) elements.item(i);
    boolean nested = e.getElementsByTagName("column").getLength() > 0
            || e.getElementsByTagName("formula").getLength() > 0;
    if (!e.getAttribute("column").isEmpty() && nested)
        throw new IllegalStateException("<" + e.getTagName() + "> mixes column attribute with nested column/formula");
}

Try / catch

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

Prevention

When it happens

Trigger: An element such as <many-to-one name='a' column='a_id'> that also contains a nested <column name='a_fk'/> (or <formula/>) child.

Common situations: Adding detailed column configuration as a nested element without removing the shorthand attribute; merging mappings; templates pre-filling column= on every element.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/616268b6fb12f50c. Report an issue: GitHub.