hibernate/hibernate-orm · error · AnnotationException
An association that targets entity '" + referencedEntity.get
Error message
An association that targets entity '" + referencedEntity.getEntityName() + "' from entity '" + associatedClass.getEntityName() + "' has no '@JoinColumn' referencing column '" + key.getColumns().get(j).getName() + "'
What it means
Error "An association that targets entity '" + referencedEntity.getEntityName() + "' from entity '" + associatedClass.getEntityName() + "' has no '@JoinColumn' referencing column '" + key.getColumns().get(j).getName() + "'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java:669
private static void bindPrimaryKeyReference(
PersistentClass referencedEntity,
AnnotatedJoinColumns joinColumns,
SimpleValue value,
PersistentClass associatedClass,
MetadataBuildingContext buildingContext) {
// ensure the composite key is sorted so that we can simply
// set sorted to true on the ToOne (below)
final var key = referencedEntity.getKey();
if ( key instanceof Component component ) {
component.sortProperties();
}
// works because the pk has to be on the primary table
final var metadataCollector = buildingContext.getMetadataCollector();
final var dialect = metadataCollector.getDatabase().getJdbcEnvironment().getDialect();
for ( int j = 0; j < key.getColumnSpan(); j++ ) {
if ( !matchUpJoinColumnsWithKeyColumns( referencedEntity, joinColumns, value, metadataCollector, dialect, j ) ) {
// we can only get here if there's a dupe PK column in the @JoinColumns
throw new AnnotationException(
"An association that targets entity '" + referencedEntity.getEntityName()
+ "' from entity '" + associatedClass.getEntityName()
+ "' has no '@JoinColumn' referencing column '" + key.getColumns().get(j).getName() + "'"
);
}
}
if ( value instanceof ToOne toOne ) {
toOne.setSorted( true );
}
else if ( value instanceof DependantValue dependantValue ) {
dependantValue.setSorted( true );
}
else {
throw new AssertionError(
"This should never happen, value can only be ToOne or DependantValue," +
"instead it's '" + value.getClass().getName() + "'"
);
}View on GitHub (pinned to fad1729dce)
Solutions
- Add a @JoinColumn referencing the missing primary key column of the target entity.
When it happens
Trigger: A '@JoinColumn' / 'referencedColumnName' does not line up with the columns mapped by the target entity.
Common situations: Composite foreign keys, associations to entities with secondary tables, or reordered/duplicated referencedColumnName values across multiple @JoinColumn declarations.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e69438bc5efe7c90.
Report an issue: GitHub.