{"record":{"id":"920a64bb46e4a077","repo":"hibernate/hibernate-orm","slug":"association-s-is-mappedby-a-property-s-of","errorCode":null,"errorMessage":"Association '%s' is 'mappedBy' a property '%s' of entity '%s' with no columns","messagePattern":"Association '(.+?)' is 'mappedBy' a property '(.+?)' of entity '(.+?)' with no columns","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java","lineNumber":608,"sourceCode":"\t\t\treturn referencedTableName;\n\t\t}\n\n\t\t@Override\n\t\tpublic Identifier getReferencedColumnName() {\n\t\t\tif ( logicalReferencedColumn != null ) {\n\t\t\t\treturn database.toIdentifier( logicalReferencedColumn );\n\t\t\t}\n\n\t\t\tif ( getMappedByEntityName() == null || getMappedByPropertyName() == null ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfinal var mappedByProperty =\n\t\t\t\t\tcollector.getEntityBinding( getMappedByEntityName() )\n\t\t\t\t\t\t\t.getProperty( getMappedByPropertyName() );\n\t\t\tfinal var value = (SimpleValue) mappedByProperty.getValue();\n\t\t\tif ( value.getSelectables().isEmpty() ) {\n\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\t\t\"Association '%s' is 'mappedBy' a property '%s' of entity '%s' with no columns\",\n\t\t\t\t\t\t\t\tgetPropertyHolder().getPath(),\n\t\t\t\t\t\t\t\tgetMappedByPropertyName(),\n\t\t\t\t\t\t\t\tgetMappedByEntityName()\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ( !(value.getSelectables().get( 0 ) instanceof Column column) ) {\n\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\t\t\"Association '%s' is 'mappedBy' a property '%s' of entity '%s' which maps to a formula\",\n\t\t\t\t\t\t\t\tgetPropertyHolder().getPath(),\n\t\t\t\t\t\t\t\tgetMappedByPropertyName(),\n\t\t\t\t\t\t\t\tgetPropertyHolder().getPath()\n\t\t\t\t\t\t)","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java#L590-L626","documentation":"To complete this inverse association, Hibernate resolves the property it is 'mappedBy' and needs its single mapped column (e.g. to derive a default ordering/foreign key). The resolved property's value has ZERO selectables — it maps to no column at all — so no column can be derived and the mapping is rejected.","triggerScenarios":"'@OneToMany(mappedBy = \"x\")' where property x on the target entity is a @Transient-like value mapped only by a @Formula, an association with no join column yet, or an embedded value that produced no selectables at this phase; mappedBy pointing at a property that failed to bind columns earlier.","commonSituations":"Renaming fields so mappedBy now points at a stale property; mappedBy referencing a formula-based or transient-ish property; ordering of bindings during partial mappings in tests.","solutions":["Point mappedBy at the actual OWNING side property (the @ManyToOne/@OneToOne with a real @JoinColumn).","Make sure that owning property maps a real column (plain @ManyToOne + @JoinColumn, no @Formula).","Verify spelling/case of the mappedBy string against the target entity's field names."],"exampleFix":"// before\n@Entity\nclass Post {\n    @OneToMany(mappedBy = \"postRef\") // Post.body has no columns\n    List<Comment> comments;\n}\n\n// after\n@Entity\nclass Post {\n    @OneToMany(mappedBy = \"post\")\n    List<Comment> comments;\n}\n\n@Entity\nclass Comment {\n    @ManyToOne(fetch = FetchType.LAZY)\n    @JoinColumn(name = \"post_id\")\n    Post post; // real column owner\n}","handlingStrategy":"validation","validationCode":"// Guard: mappedBy must name a property that maps a real column\nString mappedBy = \"post\";\nField owner = Comment.class.getDeclaredField(mappedBy);\nboolean hasColumn = owner.isAnnotationPresent(ManyToOne.class)\n    || owner.isAnnotationPresent(OneToOne.class);\nif (!hasColumn) throw new IllegalStateException(\n    \"mappedBy '\" + mappedBy + \"' on Comment does not map a column-backed association\");","typeGuard":null,"tryCatchPattern":"try {\n    factory = cfg.buildSessionFactory();\n} catch (AnnotationException e) {\n    // 'is mappedBy a property ... with no columns' -> point mappedBy at the\n    // column-backed @ManyToOne/@OneToOne owner\n    throw newConfigurationException(\"Invalid mappedBy target\", e);\n}","preventionTips":["Always let the IDE resolve mappedBy strings to a real field; unresolved strings are a bug.","Keep the owning side a plain @ManyToOne + @JoinColumn; avoid formula-only owners.","Update both sides of a bidirectional pair in the same refactor."],"tags":["hibernate","jpa","mappedby","orm-mapping"],"backgroundTag":"mappedby-misuse","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}