hibernate/hibernate-orm · error · TransformationException
Error transforming many-to-any :
Error message
Error transforming many-to-any :
What it means
Thrown by HbmXmlTransformer when transformPluralAny fails for a collection declared with <many-to-any/>. In current Hibernate this catch is effectively always hit together with error 365: transferPluralAny unconditionally throws UnsupportedOperationException('Not yet implemented'), which this TransformationException then wraps along with the mapping Origin.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java:2239
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 ) );
}
catch (Exception e) {
throw new TransformationException( "Error transforming many-to-any : " + hbmCollection.getName(), e, origin() );
}
}
else {
throw new UnsupportedOperationException( "Unexpected node type - " + hbmCollection );
}
}
}
}
private JaxbBasicImpl transformBasicAttribute(final JaxbHbmBasicAttributeType hbmProp, PropertyInfo propertyInfo) {
final var basic = new JaxbBasicImpl();
transferBasicAttribute( hbmProp, basic, propertyInfo );
return basic;
}
private void transferBasicAttribute(
JaxbHbmBasicAttributeType hbmProp,
JaxbBasicImpl basic,View on GitHub (pinned to fad1729dce)
Solutions
- Treat this as an unimplemented feature, not a bug in your mapping: plural <any/> transformation is not implemented
- Exclude mappings containing <many-to-any> from the transformation and keep them as native hbm.xml (Hibernate 6 binds hbm.xml directly)
- Or hand-write the equivalent mapping.xml attribute for that collection
- Or remodel the association as a normal many-to-many/entity hierarchy with an explicit discriminator entity
Example fix
// before: transforming a mapping that contains
// <set name="targets"><key column="..."/><many-to-any meta-type="string">...</many-to-any></set>
transformer.transform(hbmSource); // -> TransformationException
// after: skip transformation for that file, bind it natively
metadataSources.addFile("targets.hbm.xml"); // Hibernate 6 still supports hbm.xml directly Defensive patterns
Strategy: validation
Validate before calling
// detect <many-to-any> before running the transformer
var doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(hbmFile);
if (doc.getElementsByTagName("many-to-any").getLength() > 0) {
throw new UnsupportedOperationException(
hbmFile + " contains <many-to-any>: plural any transformation is not implemented; bind this file as native hbm.xml");
} Try / catch
try {
transformer.transform(hbmSource);
} catch (TransformationException e) {
if (e.getCause() instanceof UnsupportedOperationException) {
// plural any is unimplemented - keep this mapping native hbm.xml
metadataSources.addFile(nativeHbmPath);
} else { throw e; }
} Prevention
- Pre-scan hbm files for many-to-any before deciding to transform
- Keep a list of untransformable files bound natively alongside transformed output
- Watch Hibernate release notes for plural-any transformation support
When it happens
Trigger: Any hbm.xml containing a <many-to-any> element (heterogeneous collections keyed by a meta-type discriminator) passed through the hbm-to-mapping.xml transformation. The failure is deterministic, not data-dependent.
Common situations: Legacy polymorphic collection mappings (e.g., an 'attachments' set that can hold any entity type); attempting bulk migration of old hbm.xml files to mapping.xml.
Related errors
- Not yet implemented
- Error transforming element-collection :
- Error transforming one-to-many :
- Error transforming many-to-many :
- Unexpected node type -
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ee34e02309b06320.
Report an issue: GitHub.