{"record":{"id":"c62c562f64968c61","repo":"hibernate/hibernate-orm","slug":"association-is-mappedby-a-property-named","errorCode":null,"errorMessage":"Association '{}' is 'mappedBy' a property named '{}' which references the wrong entity type '{}', expected '{}'","messagePattern":"Association '(.+?)' is 'mappedBy' a property named '(.+?)' which references the wrong entity type '(.+?)', expected '(.+?)'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java","lineNumber":977,"sourceCode":"\n\tprivate static void checkMappedByType(\n\t\t\tString mappedBy,\n\t\t\tString propertyName,\n\t\t\tPropertyHolder propertyHolder,\n\t\t\tMap<String, PersistentClass> persistentClasses,\n\t\t\tToOne toOne) {\n\t\tfinal String referencedEntityName = toOne.getReferencedEntityName();\n\t\tfinal PersistentClass referencedClass = persistentClasses.get( referencedEntityName );\n\t\tPersistentClass ownerClass = propertyHolder.getPersistentClass();\n\t\twhile ( ownerClass != null ) {\n\t\t\tif ( checkReferencedClass( ownerClass, referencedClass ) ) {\n\t\t\t\t// the two entities map to the same table, so we are good\n\t\t\t\treturn;\n\t\t\t}\n\t\t\townerClass = ownerClass.getSuperPersistentClass();\n\t\t}\n\t\t// we could not find any entity mapping to the same table\n\t\tthrow new AnnotationException(\n\t\t\t\t\"Association '\" + qualify( propertyHolder.getPath(), propertyName )\n\t\t\t\t+ \"' is 'mappedBy' a property named '\" + mappedBy\n\t\t\t\t+ \"' which references the wrong entity type '\" + referencedEntityName\n\t\t\t\t+ \"', expected '\" + propertyHolder.getEntityName() + \"'\"\n\t\t);\n\t}\n\n\tprivate static boolean checkReferencedClass(PersistentClass ownerClass, PersistentClass referencedClass) {\n\t\twhile ( referencedClass != null ) {\n\t\t\t// Allow different entity types as long as they map to the same table\n\t\t\tif ( ownerClass.getTable() == referencedClass.getTable() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treferencedClass = referencedClass.getSuperPersistentClass();\n\t\t}\n\t\treturn false;\n\t}\n","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java#L959-L995","documentation":"Error \"Association '{}' is 'mappedBy' a property named '{}' which references the wrong entity type '{}', expected '{}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An association declares 'mappedBy' naming a property that does not exist, has the wrong type, or is not the owning side on the target entity.","commonSituations":"Bidirectional associations where mappedBy is misspelled, both sides claim ownership, or the target entity was refactored without updating the mapping.","solutions":["Correct the mappedBy value to reference a property of the expected entity type.","Or fix the association target type so the mappedBy property belongs to it."],"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"}