{"record":{"id":"ee34e02309b06320","repo":"hibernate/hibernate-orm","slug":"error-transforming-many-to-any","errorCode":null,"errorMessage":"Error transforming many-to-any : ","messagePattern":"Error transforming many-to-any : ","errorType":"exception","errorClass":"TransformationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java","lineNumber":2239,"sourceCode":"\t\t\t\telse if ( hbmCollection.getManyToMany() != null ) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif ( hbmCollection.getManyToMany().isUnique() ) {\n\t\t\t\t\t\t\tattributes.getOneToManyAttributes().add( transformManyToManyToOneToMany( hbmCollection, propertyInfo ) );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tattributes.getManyToManyAttributes().add( transformManyToMany( hbmCollection, propertyInfo ) );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\tthrow new TransformationException( \"Error transforming many-to-many : \" + hbmCollection.getName(), e, origin() );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if ( hbmCollection.getManyToAny() != null ) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tattributes.getPluralAnyMappingAttributes().add( transformPluralAny( hbmCollection ) );\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\tthrow new TransformationException( \"Error transforming many-to-any : \" + hbmCollection.getName(), e, origin() );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new UnsupportedOperationException( \"Unexpected node type - \" + hbmCollection );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate JaxbBasicImpl transformBasicAttribute(final JaxbHbmBasicAttributeType hbmProp, PropertyInfo propertyInfo) {\n\t\tfinal var basic = new JaxbBasicImpl();\n\t\ttransferBasicAttribute( hbmProp, basic, propertyInfo );\n\t\treturn basic;\n\t}\n\n\tprivate void transferBasicAttribute(\n\t\t\tJaxbHbmBasicAttributeType hbmProp,\n\t\t\tJaxbBasicImpl basic,","sourceCodeStart":2221,"sourceCodeEnd":2257,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java#L2221-L2257","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: transforming a mapping that contains\n// <set name=\"targets\"><key column=\"...\"/><many-to-any meta-type=\"string\">...</many-to-any></set>\ntransformer.transform(hbmSource); // -> TransformationException\n\n// after: skip transformation for that file, bind it natively\nmetadataSources.addFile(\"targets.hbm.xml\"); // Hibernate 6 still supports hbm.xml directly","handlingStrategy":"validation","validationCode":"// detect <many-to-any> before running the transformer\nvar doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(hbmFile);\nif (doc.getElementsByTagName(\"many-to-any\").getLength() > 0) {\n    throw new UnsupportedOperationException(\n        hbmFile + \" contains <many-to-any>: plural any transformation is not implemented; bind this file as native hbm.xml\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    transformer.transform(hbmSource);\n} catch (TransformationException e) {\n    if (e.getCause() instanceof UnsupportedOperationException) {\n        // plural any is unimplemented - keep this mapping native hbm.xml\n        metadataSources.addFile(nativeHbmPath);\n    } else { throw e; }\n}","preventionTips":["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"],"tags":["hibernate","hbm-xml","many-to-any","mapping-transformation","unsupported-feature"],"backgroundTag":"unsupported-orm-mapping-feature","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}