hibernate/hibernate-orm · error · AnnotationException
Association '%s' is 'mappedBy' a property '%s' of entity '%s
Error message
Association '%s' is 'mappedBy' a property '%s' of entity '%s' with no columns
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java:608
return referencedTableName;
}
@Override
public Identifier getReferencedColumnName() {
if ( logicalReferencedColumn != null ) {
return database.toIdentifier( logicalReferencedColumn );
}
if ( getMappedByEntityName() == null || getMappedByPropertyName() == null ) {
return null;
}
final var mappedByProperty =
collector.getEntityBinding( getMappedByEntityName() )
.getProperty( getMappedByPropertyName() );
final var value = (SimpleValue) mappedByProperty.getValue();
if ( value.getSelectables().isEmpty() ) {
throw new AnnotationException(
String.format(
Locale.ENGLISH,
"Association '%s' is 'mappedBy' a property '%s' of entity '%s' with no columns",
getPropertyHolder().getPath(),
getMappedByPropertyName(),
getMappedByEntityName()
)
);
}
if ( !(value.getSelectables().get( 0 ) instanceof Column column) ) {
throw new AnnotationException(
String.format(
Locale.ENGLISH,
"Association '%s' is 'mappedBy' a property '%s' of entity '%s' which maps to a formula",
getPropertyHolder().getPath(),
getMappedByPropertyName(),
getPropertyHolder().getPath()
)View on GitHub (pinned to fad1729dce)
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.
Example fix
// before
@Entity
class Post {
@OneToMany(mappedBy = "postRef") // Post.body has no columns
List<Comment> comments;
}
// after
@Entity
class Post {
@OneToMany(mappedBy = "post")
List<Comment> comments;
}
@Entity
class Comment {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
Post post; // real column owner
} Defensive patterns
Strategy: validation
Validate before calling
// Guard: mappedBy must name a property that maps a real column
String mappedBy = "post";
Field owner = Comment.class.getDeclaredField(mappedBy);
boolean hasColumn = owner.isAnnotationPresent(ManyToOne.class)
|| owner.isAnnotationPresent(OneToOne.class);
if (!hasColumn) throw new IllegalStateException(
"mappedBy '" + mappedBy + "' on Comment does not map a column-backed association"); Try / catch
try {
factory = cfg.buildSessionFactory();
} catch (AnnotationException e) {
// 'is mappedBy a property ... with no columns' -> point mappedBy at the
// column-backed @ManyToOne/@OneToOne owner
throw newConfigurationException("Invalid mappedBy target", e);
} Prevention
- 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.
When it happens
Trigger: '@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.
Common situations: 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.
Related errors
- Association '%s' of entity '%s' is 'mappedBy' a different en
- Association '%s' is 'mappedBy' a property '%s' of entity '%s
- Association '%s' is 'mappedBy' a property '%s' of entity '%s
- Class '<componentClassName>' is an '@Embeddable' type and ma
- Property '<propertyName>' may not be annotated '@BatchSize'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/920a64bb46e4a077.
Report an issue: GitHub.