{"record":{"id":"780e840cec231794","repo":"hibernate/hibernate-orm","slug":"a-joincolumn-for-association-references-a","errorCode":null,"errorMessage":"A '@JoinColumn' for association '{}' references a column named '{}' which is not mapped by the target entity '{}'","messagePattern":"A '@JoinColumn' for association '(.+?)' references a column named '(.+?)' which is not mapped by the target entity '(.+?)'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java","lineNumber":198,"sourceCode":"\t/**\n\t * All the referenced columns must belong to the same table, that is\n\t * {@link #findColumnOwner(PersistentClass, String, MetadataBuildingContext)}\n\t * must return the same value for all of them.\n\t */\n\tprivate static void checkColumnInSameTable(\n\t\t\tAnnotatedJoinColumns joinColumns,\n\t\t\tPersistentClass targetEntity,\n\t\t\tPersistentClass associatedEntity,\n\t\t\tMetadataBuildingContext context,\n\t\t\tAttributeContainer columnOwner) {\n\t\tif ( joinColumns.hasMappedBy() ) {\n\t\t\t// we should only get called for owning side of association\n\t\t\tthrow new AssertionFailure(\"no need to create synthetic properties for unowned collections\");\n\t\t}\n\t\tfor ( var column: joinColumns.getJoinColumns() ) {\n\t\t\tfinal var owner = findReferencedColumnOwner( targetEntity, column, context );\n\t\t\tif ( owner == null ) {\n\t\t\t\tthrow new AnnotationException( \"A '@JoinColumn' for association \"\n\t\t\t\t\t\t+ associationMessage( associatedEntity, joinColumns )\n\t\t\t\t\t\t+ \" references a column named '\" + column.getReferencedColumn()\n\t\t\t\t\t\t+ \"' which is not mapped by the target entity '\"\n\t\t\t\t\t\t+ targetEntity.getEntityName() + \"'\" );\n\t\t\t}\n\t\t\tif ( owner != columnOwner) {\n\t\t\t\tfinal var firstColumn = joinColumns.getJoinColumns().get(0);\n\t\t\t\tthrow new AnnotationException( \"The '@JoinColumn's for association \"\n\t\t\t\t\t\t+ associationMessage( associatedEntity, joinColumns )\n\t\t\t\t\t\t+ \" reference columns of different tables mapped by the target entity '\"\n\t\t\t\t\t\t+ targetEntity.getEntityName() + \"' ('\" + column.getReferencedColumn() +\n\t\t\t\t\t\t\"' belongs to a different table to '\" + firstColumn.getReferencedColumn() + \"'\" );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If the referenced columns correspond to exactly one property","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java#L180-L216","documentation":"Error \"A '@JoinColumn' for association '{}' references a column named '{}' which is not mapped by the target entity '{}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A '@JoinColumn' / 'referencedColumnName' does not line up with the columns mapped by the target entity.","commonSituations":"Composite foreign keys, associations to entities with secondary tables, or reordered/duplicated referencedColumnName values across multiple @JoinColumn declarations.","solutions":["Change referencedColumnName of the @JoinColumn to a column actually mapped by the target entity.","Or map the column on the target entity so the join column can reference 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"}