{"record":{"id":"c636d5edde333c35","repo":"hibernate/hibernate-orm","slug":"encountered-multiple-component-mappings-for-the-sa","errorCode":null,"errorMessage":"Encountered multiple component mappings for the same java class {embeddableClassName} with different property mappings. Every property mapping combination should have its own java class","messagePattern":"Encountered multiple component mappings for the same java class (.+?) with different property mappings\\. Every property mapping combination should have its own java class","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java","lineNumber":901,"sourceCode":"\t}\n\n\tpublic EmbeddableDomainType<?> locateEmbeddable(Class<?> embeddableClass, Component component) {\n\t\tfinal var domainType = embeddables.get( embeddableClass );\n\t\tif ( domainType != null ) {\n\t\t\treturn domainType;\n\t\t}\n\t\telse {\n\t\t\tfinal var embeddableDomainTypes = embeddablesToProcess.get( embeddableClass );\n\t\t\tif ( embeddableDomainTypes != null ) {\n\t\t\t\tfor ( var embeddableDomainType : embeddableDomainTypes ) {\n\t\t\t\t\tfinal var cachedComponent = componentByEmbeddable.get( embeddableDomainType );\n\t\t\t\t\tif ( cachedComponent.isSame( component ) ) {\n\t\t\t\t\t\treturn embeddableDomainType;\n\t\t\t\t\t}\n\t\t\t\t\telse if ( cachedComponent.getComponentClass().equals( component.getComponentClass() ) ) {\n\t\t\t\t\t\tfinal int cachedComponentPropertySpan = cachedComponent.getPropertySpan();\n\t\t\t\t\t\tif ( cachedComponentPropertySpan != component.getPropertySpan() ) {\n\t\t\t\t\t\t\tthrow new MappingException( \"Encountered multiple component mappings for the same java class \"\n\t\t\t\t\t\t\t\t\t\t\t+ embeddableClass.getName() +\n\t\t\t\t\t\t\t\t\t\t\t\" with different property mappings. Every property mapping combination should have its own java class\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tfor ( int i = 0; i < cachedComponentPropertySpan; i++ ) {\n\t\t\t\t\t\t\t\tif ( !cachedComponent.getProperty( i ).getName()\n\t\t\t\t\t\t\t\t\t\t.equals( component.getProperty( i ).getName() ) ) {\n\t\t\t\t\t\t\t\t\tthrow new MappingException( \"Encountered multiple component mappings for the same java class \"\n\t\t\t\t\t\t\t\t\t\t\t\t\t+ embeddableClass.getName() +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\" with different property mappings. Every property mapping combination should have its own java class\" );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn embeddableDomainType;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new MappingException( \"Encountered multiple component mappings for the same java class \"\n\t\t\t\t\t\t\t\t\t\t+ embeddableClass.getName() +","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java#L883-L919","documentation":"A MappingException raised by MetadataContext.locateEmbeddable during JPA metamodel/bootstrap processing when the same embeddable Java class is encountered in two component mappings that declare different numbers of properties. Hibernate keys embeddable domain types by Java class; a cached Component for that class with a different property span (cachedComponentPropertySpan != component.getPropertySpan()) proves the class is being mapped with inconsistent attribute sets, which the JPA model cannot represent, so bootstrap fails demanding one Java class per property-mapping combination.","triggerScenarios":"Two entities embedding the same class where one mapping lists a subset of the fields (e.g. hbm.xml <component> blocks each enumerating different <property> lists); one mapping applying @AttributeOverrides/@Transient-style exclusions so the persisted attribute set differs; XML components generated by different teams for the same class.","commonSituations":"Legacy hbm.xml components reusing one class with per-mapping property lists; mappings where a field was added to the embeddable and only one of several embedding mappings was updated; annotation mappings using different column/attribute subsets of a shared embeddable.","solutions":["Give each distinct property combination its own Java class (extract a smaller record/class for the subset mapping)","Make every mapping of that embeddable declare exactly the same property list (same names, same order, same count)","If only column names differ, keep the attribute set identical and use @AttributeOverrides/@Column to change just the columns","Verify with sessionFactory.getMetamodel() in a smoke test that both mappings can coexist at boot"],"exampleFix":"<!-- before - same class, different property counts -->\n<component name=\"home\" class=\"Address\">\n    <property name=\"street\" column=\"HOME_STREET\"/>\n    <property name=\"city\" column=\"HOME_CITY\"/>\n</component>\n<component name=\"billing\" class=\"Address\">\n    <property name=\"street\" column=\"BILL_STREET\"/>\n    <!-- city omitted -->\n</component>\n\n<!-- after - same attribute set everywhere (columns may differ) -->\n<component name=\"billing\" class=\"Address\">\n    <property name=\"street\" column=\"BILL_STREET\"/>\n    <property name=\"city\" column=\"BILL_CITY\"/>\n</component>","handlingStrategy":"validation","validationCode":"// Assert every mapping of an embeddable class declares the same attribute set\nMap<Class<?>, Set<List<String>>> byClass = new HashMap<>();\nfor ( Mapping m : allComponentMappings() ) {\n    byClass.computeIfAbsent(m.getComponentClass(), k -> new HashSet<>()).add(m.attributeNamesInOrder());\n}\nfor ( var e : byClass.entrySet() ) {\n    if ( e.getValue().size() > 1 ) {\n        throw new IllegalStateException(\"Embeddable \" + e.getKey() + \" mapped with different attribute sets: \" + e.getValue());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    EntityManagerFactory emf = Persistence.createEntityManagerFactory(\"pu\");\n}\ncatch ( org.hibernate.mapping.MappingException e ) {\n    if ( e.getMessage() != null && e.getMessage().contains(\"multiple component mappings for the same java class\") ) {\n        throw new ConfigurationError(\"Split the embeddable into one class per property-mapping combination - \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["One embeddable class per distinct attribute combination - do not reuse across subset mappings","Keep attribute lists (count, names, order) identical in every mapping of a shared embeddable","Use @AttributeOverrides for column differences instead of trimming attribute lists"],"tags":["hibernate","jpa","embeddable","component-mapping","metamodel","bootstrap"],"backgroundTag":"embeddable-reused-across-mappings","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}