{"record":{"id":"879294911ba58d94","repo":"hibernate/hibernate-orm","slug":"association-role-targets-the-type-type-w","errorCode":null,"errorMessage":"Association '${role}' targets the type '${type}' which does not belong to the same persistence unit","messagePattern":"Association '(.+?)' targets the type '(.+?)' which does not belong to the same persistence unit","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java","lineNumber":269,"sourceCode":"\t\t\t\t\t\t.getClassDetailsRegistry()\n\t\t\t\t\t\t.resolveClassDetails( mapKeyType );\n\t}\n\n\tprivate static String getKeyType(MemberDetails property) {\n\t\t//target has priority over reflection for the map key type\n\t\t//JPA 2 has priority\n\t\tfinal var mapKeyClassAnn = property.getDirectAnnotationUsage( MapKeyClass.class );\n\t\tfinal var target = mapKeyClassAnn != null ? mapKeyClassAnn.value() : void.class;\n\t\treturn void.class.equals( target ) ? property.getMapKeyType().getName() : target.getName();\n\t}\n\n\tprivate void handleMapKeyProperty(\n\t\t\tTypeDetails elementType,\n\t\t\tjava.util.Map<String, PersistentClass> persistentClasses,\n\t\t\tString mapKeyPropertyName) {\n\t\tfinal var associatedClass = persistentClasses.get( elementType.getName() );\n\t\tif ( associatedClass == null ) {\n\t\t\tthrow new AnnotationException( \"Association '\" + safeCollectionRole() + \"'\"\n\t\t\t\t\t+ targetEntityMessage( elementType ) );\n\t\t}\n\t\tfinal Property mapProperty = findPropertyByName( associatedClass, mapKeyPropertyName );\n\t\tif ( mapProperty == null ) {\n\t\t\tthrow new AnnotationException( \"Map key property '\" + mapKeyPropertyName\n\t\t\t\t\t+ \"' not found in target entity '\" + associatedClass.getEntityName() + \"'\" );\n\t\t}\n\t\t// HHH-11005 - if InheritanceType.JOINED then need to find class defining the column\n\t\tfinal var targetEntity =\n\t\t\t\tinheritanceStatePerClass.get( elementType.determineRawClass() ).getType() == InheritanceType.JOINED\n\t\t\t\t\t\t? mapProperty.getPersistentClass()\n\t\t\t\t\t\t: associatedClass;\n\t\tfinal Value indexValue =\n\t\t\t\tcreateFormulatedValue( mapProperty.getValue(), collection, associatedClass, targetEntity );\n\t\tgetMap().setIndex( indexValue );\n\t\tgetMap().setMapKeyPropertyName( mapKeyPropertyName );\n\t}\n","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java#L251-L287","documentation":"Error \"Association '${role}' targets the type '${type}' which does not belong to the same persistence unit\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An association or reference targets a type that Hibernate has not mapped as an entity.","commonSituations":"Missing @Entity on the target class, the class not being scanned into the persistence unit, or a typo in the entity name.","solutions":["Include the target type in the same persistence unit, or change the association target."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}