hibernate/hibernate-orm · error · MappingException

Attribute mapping must define a name attribute: containingCl

Error message

Attribute mapping must define a name attribute: containingClassName=[%s], propertyName=[%s], role=[%s]

What it means

Hibernate determines many attribute types by reflecting on containingClassName.propertyName (value.setTypeUsingReflection). If the mapping element carries no usable name (StringHelper.isEmpty(propertyName) is true), there is nothing to resolve and the binder aborts before even attempting reflection. This is a structural mapping defect, not a classpath problem.

Source

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

	private Object typeInstance(String typeName, Class<?> typeJavaType) {
		if ( !metadataBuildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) {
			return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( typeJavaType );
		}
		else {
			final String beanName = typeName + ":" + TypeDefinition.NAME_COUNTER.getAndIncrement();
			return metadataBuildingContext.getBootstrapContext().getManagedBeanRegistry()
					.getBean( beanName, typeJavaType ).getBeanInstance();
		}
	}

	private void prepareValueTypeViaReflection(
			MappingDocument sourceDocument,
			Value value,
			String containingClassName,
			String propertyName,
			AttributeRole attributeRole) {
		if ( StringHelper.isEmpty( propertyName ) ) {
			throw new MappingException(
					"Attribute mapping must define a name attribute:"
					+ " containingClassName=[%s], propertyName=[%s], role=[%s]"
							.formatted( containingClassName, propertyName,
									attributeRole.getFullPath() ),
					sourceDocument.getOrigin()
			);
		}

		try {
			value.setTypeUsingReflection( containingClassName, propertyName );
		}
		catch (MappingException ome) {
			throw new MappingException(
					"Error calling Value#setTypeUsingReflection:"
					+ " containingClassName=[%s], propertyName=[%s], role=[%s]"
							.formatted( containingClassName, propertyName,
									attributeRole.getFullPath() ),
					ome,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add the name attribute to the property element
  2. Or supply an explicit type attribute so reflection is not required
  3. Validate hbm.xml against the XSD in CI to catch name-less property elements early

Example fix

// before
<property column='email' type='string'/>

// after
<property name='email' column='email' type='string'/>
Defensive patterns

Strategy: validation

Validate before calling

// reject any value-mapping element that has neither name nor type
String[] valued = {"property", "many-to-one", "one-to-one", "component", "any"};
for (String tag : valued) {
    NodeList nodes = doc.getElementsByTagName(tag);
    for (int i = 0; i < nodes.getLength(); i++) {
        Element e = (Element) nodes.item(i);
        boolean noName = e.getAttributeNode("name") == null || e.getAttribute("name").isBlank();
        boolean noType = e.getAttributeNode("type") == null;
        if (noName && noType) {
            throw new IllegalStateException("<" + tag + "> must define name or type");
        }
    }
}

Try / catch

catch (MappingException e) at bootstrap; the message prints containingClassName, propertyName, and the attribute role. Add the missing name= (or an explicit type=) to the element the role points at.

Prevention

When it happens

Trigger: A property mapping element in hbm.xml without a name= attribute where an inline type was also not supplied, forcing the reflection path; programmatically built attribute sources that omit the name.

Common situations: Hand-written hbm.xml with a missing name attribute; templates or code generators emitting empty property elements; accidental deletion of the name attribute during editing.

Related errors


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