{"record":{"id":"6d2c5c1268392106","repo":"hibernate/hibernate-orm","slug":"association-path-is-mappedby-a-property-nam-6d2c5c","errorCode":null,"errorMessage":"Association '${path}' is 'mappedBy' a property named '${mappedBy}' which does not exist in the target entity type '${type}'","messagePattern":"Association '(.+?)' is 'mappedBy' a property named '(.+?)' which does not exist in the target entity type '(.+?)'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/OneToOneSecondPass.java","lineNumber":183,"sourceCode":"\t\tmanyToOne.setLazy( oneToOne.isLazy() );\n\t\tmanyToOne.setReferencedEntityName( oneToOne.getReferencedEntityName() );\n\t\tmanyToOne.setReferencedPropertyName( mappedBy );\n\t\tmanyToOne.setUnwrapProxy( oneToOne.isUnwrapProxy() );\n\t\tmanyToOne.markAsLogicalOneToOne();\n\t\treturn manyToOne;\n\t}\n\n\tprivate Property targetProperty(OneToOne oneToOne, PersistentClass targetEntity) {\n\t\ttry {\n\t\t\tfinal var targetProperty = findPropertyByName( targetEntity, mappedBy );\n\t\t\tif ( targetProperty != null ) {\n\t\t\t\treturn targetProperty;\n\t\t\t}\n\t\t}\n\t\tcatch (MappingException e) {\n\t\t\t// swallow it\n\t\t}\n\t\tthrow new AnnotationException( \"Association '\" + getPath( propertyHolder, inferredData )\n\t\t\t\t+ \"' is 'mappedBy' a property named '\" + mappedBy\n\t\t\t\t+ \"' which does not exist in the target entity type '\" + oneToOne.getReferencedEntityName() + \"'\" );\n\t}\n\n\tprivate void bindOwned(\n\t\t\tMap<String, PersistentClass> persistentClasses,\n\t\t\tOneToOne oneToOne,\n\t\t\tString propertyName) {\n\t\tfinal ToOneFkSecondPass secondPass = new ToOneFkSecondPass(\n\t\t\t\toneToOne,\n\t\t\t\tjoinColumns,\n\t\t\t\ttrue,\n\t\t\t\tannotatedEntity,\n\t\t\t\tpropertyHolder.getPersistentClass(),\n\t\t\t\tqualify( propertyHolder.getPath(), propertyName ),\n\t\t\t\tbuildingContext\n\t\t);\n\t\tsecondPass.doSecondPass(persistentClasses);","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/OneToOneSecondPass.java#L165-L201","documentation":"The mappedBy attribute of a @OneToOne names a property on the target entity, and Hibernate could not find any property with that name (findPropertyByName returned null or threw). Without the inverse property the association cannot be wired, so AnnotationException is thrown at bootstrap.","triggerScenarios":"@OneToOne(mappedBy = \"usr\") where the target entity's field is actually called 'user'; target entity different from the one assumed (targetEntity pointing to the wrong class); property renamed without updating mappedBy; Kotlin/Java name mismatch (field vs accessor naming).","commonSituations":"Typos in mappedBy values; renaming the owning field via IDE refactor that does not update string-based references; copy-pasting an association between entity pairs; Lombok/records changing the effective property name.","solutions":["Open the target entity and copy the exact Java property name of the owning side into mappedBy.","If the owning field was renamed, update every mappedBy that references the old name.","Verify targetEntity (explicit or inferred from the field type) really is the class that holds the owning property."],"exampleFix":"// before\npublic class User {\n    @OneToOne(mappedBy = \"usr\")\n    private Profile profile;\n}\npublic class Profile {\n    @OneToOne\n    @JoinColumn(name = \"user_id\")\n    private User user;\n}\n\n// after\n@OneToOne(mappedBy = \"user\")\nprivate Profile profile;","handlingStrategy":"validation","validationCode":"// Fail fast on mappedBy typos: the name must exist on the target entity\nfor (Class<?> entity : annotatedClasses) {\n    for (Field f : entity.getDeclaredFields()) {\n        OneToOne o2o = f.getAnnotation(OneToOne.class);\n        if (o2o == null || o2o.mappedBy().isEmpty()) continue;\n        try {\n            f.getType().getDeclaredField(o2o.mappedBy());\n        } catch (NoSuchFieldException e) {\n            throw new IllegalStateException(\"mappedBy '\" + o2o.mappedBy() + \"' does not exist on \" + f.getType().getSimpleName());\n        }\n    }\n}","typeGuard":"static boolean mappedByExists(Class<?> target, String mappedBy) {\n    try { target.getDeclaredField(mappedBy); return true; }\n    catch (NoSuchFieldException e) { return false; }\n}","tryCatchPattern":"try {\n    SessionFactory sf = cfg.buildSessionFactory();\n} catch (AnnotationException e) {\n    throw new IllegalStateException(\"Check mappedBy spelling: \" + e.getMessage(), e);\n}","preventionTips":["Copy-paste property names from the owning field, never type them from memory","Re-run a mapping smoke test after renaming association fields"],"tags":["hibernate","jpa","one-to-one","mappedby","association","bootstrap","typo"],"backgroundTag":"mappedby-mapping-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}