{"record":{"id":"a8910918054b181a","repo":"hibernate/hibernate-orm","slug":"the-joincolumn-s-for-association-reference-co","errorCode":null,"errorMessage":"The '@JoinColumn's for association {} reference columns of different tables mapped by the target entity '{}' ('{}' belongs to a different table to '{}'","messagePattern":"The '@JoinColumn's for association (.+?) reference columns of different tables mapped by the target entity '(.+?)' \\('(.+?)' belongs to a different table to '(.+?)'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java","lineNumber":206,"sourceCode":"\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\n\t * of the primary table of the exact target entity subclass,\n\t * just use that property. Otherwise, if a composite key is\n\t * spread out over multiple properties, then create a \"synthetic\"\n\t * {@link Component} that aggregates these properties and is\n\t * considered the target of the association. This method adds\n\t * the property holding the synthetic component to the target\n\t * entity {@link PersistentClass} by side effect.\n\t * <p>","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java#L188-L224","documentation":"Error \"The '@JoinColumn's for association {} reference columns of different tables mapped by the target entity '{}' ('{}' belongs to a different table to '{}'\" 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":["Make all @JoinColumn referencedColumnName values point to columns of the same table mapped by the target entity.","If the target maps multiple tables, join only against columns of one table, or restructure the mapping."],"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"}