{"record":{"id":"6d28be1b4a984627","repo":"hibernate/hibernate-orm","slug":"association-has-a-joincolumn-which-does-not","errorCode":null,"errorMessage":"Association {} has a '@JoinColumn' which does not specify the 'referencedColumnName' (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')","messagePattern":"Association (.+?) has a '@JoinColumn' which does not specify the 'referencedColumnName' \\(when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName'\\)","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java","lineNumber":438,"sourceCode":"\t\tclone.setValue( property.getValue() );\n\t\treturn clone;\n\t}\n\n\tprivate static List<Property> findPropertiesByColumns(\n\t\t\tAttributeContainer columnOwner,\n\t\t\tAnnotatedJoinColumns columns,\n\t\t\tPersistentClass associatedEntity,\n\t\t\tMetadataBuildingContext context) {\n\n\t\t// Build the list of column names in the exact order they were\n\t\t// specified by the @JoinColumn annotations.\n\t\tfinal List<Column> orderedColumns = new ArrayList<>( columns.getJoinColumns().size() );\n\t\tfinal Map<Column, Set<Property>> columnsToProperty = new HashMap<>();\n\t\tfinal var collector = context.getMetadataCollector();\n\t\tfinal var referencedTable = columnOwner.getTable();\n\t\tfor ( var joinColumn : columns.getJoinColumns() ) {\n\t\t\tif ( joinColumn.isReferenceImplicit() ) {\n\t\t\t\tthrow new AnnotationException( \"Association \" + associationMessage( associatedEntity, columns )\n\t\t\t\t\t\t+ \" has a '@JoinColumn' which does not specify the 'referencedColumnName'\"\n\t\t\t\t\t\t+ \" (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')\");\n\t\t\t}\n\t\t\tfinal String name = collector.getPhysicalColumnName( referencedTable, joinColumn.getReferencedColumn() );\n\t\t\tfinal var column = new Column( name );\n\t\t\torderedColumns.add( column );\n\t\t\tcolumnsToProperty.put( column, new LinkedHashSet<>() ); //need to use a LinkedHashSet here to make it deterministic\n\t\t}\n\n\t\t// Now, for each column find the properties of the target entity\n\t\t// which are mapped to that column. (There might be multiple such\n\t\t// properties for each column.)\n\t\tif ( columnOwner instanceof PersistentClass persistentClass ) {\n\t\t\t// Process ToOne associations after Components, Basic and Id properties\n\t\t\tfinal List<Property> toOneProperties = new ArrayList<>();\n\t\t\tfor ( var property : persistentClass.getReferenceableProperties() ) {\n\t\t\t\tif ( property.getValue() instanceof ToOne ) {\n\t\t\t\t\ttoOneProperties.add( property );","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java#L420-L456","documentation":"Error \"Association {} has a '@JoinColumn' which does not specify the 'referencedColumnName' (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')\" 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":["Add referencedColumnName to every @JoinColumn of the association when more than one join column is used."],"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"}