hibernate/hibernate-orm · error · TransformationException

Error transforming one-to-many :

Error message

Error transforming one-to-many : 

What it means

Thrown by HbmXmlTransformer when transformOneToMany fails for a collection declared with <one-to-many/>. It is a wrapper: the underlying exception (usually an unresolvable target entity or bad join configuration) is chained, and the Origin of the mapping is recorded. The message names the collection property that failed.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java:2218

					throw new TransformationException( "Error transforming <any/> : " + any.getName(), e, origin() );
				}
			}
			else if ( hbmAttributeMapping instanceof PluralAttributeInfo hbmCollection ) {
				final var propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmCollection.getName() );
				if ( hbmCollection.getElement() != null || hbmCollection.getCompositeElement() != null ) {
					try {
						attributes.getElementCollectionAttributes().add( transformElementCollection( roleBase, hbmCollection, propertyInfo ) );
					}
					catch (Exception e) {
						throw new TransformationException( "Error transforming element-collection : " + hbmCollection.getName(), e, origin() );
					}
				}
				else if ( hbmCollection.getOneToMany() != null ) {
					try {
						attributes.getOneToManyAttributes().add( transformOneToMany( hbmCollection, propertyInfo ) );
					}
					catch (Exception e) {
						throw new TransformationException( "Error transforming one-to-many : " + hbmCollection.getName(), e, origin() );
					}
				}
				else if ( hbmCollection.getManyToMany() != null ) {
					try {
						if ( hbmCollection.getManyToMany().isUnique() ) {
							attributes.getOneToManyAttributes().add( transformManyToManyToOneToMany( hbmCollection, propertyInfo ) );
						}
						else {
							attributes.getManyToManyAttributes().add( transformManyToMany( hbmCollection, propertyInfo ) );
						}
					}
					catch (Exception e) {
						throw new TransformationException( "Error transforming many-to-many : " + hbmCollection.getName(), e, origin() );
					}
				}
				else if ( hbmCollection.getManyToAny() != null ) {
					try {
						attributes.getPluralAnyMappingAttributes().add( transformPluralAny( hbmCollection ) );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Read exception.getCause() to get the concrete failure before touching anything
  2. Ensure the class named in <one-to-many class="..."> exists and its own mapping is included in the same metadata/transformation run
  3. Check the collection property name on the entity matches the hbm 'name' attribute
  4. Fix the reference or mapping and re-run transformation
  5. Keep the mapping as native hbm.xml if the transformer cannot express it

Example fix

<!-- before -->
<set name="items" inverse="true">
    <key column="order_id"/>
    <one-to-many class="com.acme.OrderItemTypo"/>
</set>

<!-- after -->
<set name="items" inverse="true">
    <key column="order_id"/>
    <one-to-many class="com.acme.OrderItem"/>
</set>
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the one-to-many target is part of the same mapping set before transform
Set<String> mappedClasses = hbmFiles.stream()
        .map(f -> rootEntityClassNameOf(f))
        .collect(Collectors.toSet());
String target = oneToManyClassAttrOf(hbmFile, "items");
if (!mappedClasses.contains(target)) throw new IllegalStateException("<one-to-many> target not in mapping set: " + target);

Try / catch

try {
    transformer.transform(hbmSource);
} catch (TransformationException e) {
    log.error("one-to-many transform failed: {}", e.getMessage(), e.getCause());
    // inspect e.getCause(): typically ClassNotFound / unknown entity for the target class
    throw e;
}

Prevention

When it happens

Trigger: Transforming an hbm.xml where a plural attribute has a <one-to-many class="..."> child and the referenced entity class is not on the classpath, is not part of the mapped set, or the boot model's property info for the collection is missing/inconsistent.

Common situations: Legacy parent/child hbm.xml sets where the child entity mapping file is not loaded in the same transformation run; renamed entity classes after a refactor; hbm files transformed in isolation rather than as the full unit.

Related errors


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