{"record":{"id":"5172d0a358074ee9","repo":"hibernate/hibernate-orm","slug":"referenced-column-mapped-by-target-property-5172d0","errorCode":null,"errorMessage":"Referenced column '{}' mapped by target property '{}' occurs out of order in the list of '@JoinColumn's","messagePattern":"Referenced column '(.+?)' mapped by target property '(.+?)' occurs out of order in the list of '@JoinColumn's","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java","lineNumber":540,"sourceCode":"\t\t\t\t\t\t\t+ associationMessage( associatedEntity, columns )\n\t\t\t\t\t\t\t+ \" (every column mapped by '\" + property.getName()\n\t\t\t\t\t\t\t+ \"' must occur exactly once as a 'referencedColumnName', and in the correct order)\" );\n\t\t\t\t}\n\t\t\t\telse if ( orderedProperties.contains( property ) ) {\n\t\t\t\t\t// we already used up all the columns of this property\n\t\t\t\t\tthrow new AnnotationException( \"Target property '\" + property.getName() + \"' has only \"\n\t\t\t\t\t\t\t+ property.getColumnSpan() + \" columns which may be referenced by a '@JoinColumn' for \"\n\t\t\t\t\t\t\t+ associationMessage( associatedEntity, columns )\n\t\t\t\t\t\t\t+ \" (each column mapped by '\" + property.getName()\n\t\t\t\t\t\t\t+ \"' may only occur once as a 'referencedColumnName')\" );\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// we have the first column of a new property\n\t\t\t\t\tif ( property.getColumnSpan() > 1 ) {\n\t\t\t\t\t\tif ( !property.getColumns().get(0).equals( column ) ) {\n\t\t\t\t\t\t\t// the columns have to occur in the right order in the property\n\t\t\t\t\t\t\tthrow new AnnotationException(\"Referenced column '\" + column.getName()\n\t\t\t\t\t\t\t\t\t+ \"' mapped by target property '\" + property.getName()\n\t\t\t\t\t\t\t\t\t+ \"' occurs out of order in the list of '@JoinColumn's\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentProperty = property;\n\t\t\t\t\t\tlastPropertyColumnIndex = 1;\n\t\t\t\t\t}\n\t\t\t\t\torderedProperties.add( property );\n\t\t\t\t}\n\t\t\t\tbreak; // we're only considering the first matching property for now\n\t\t\t}\n\t\t}\n\t\treturn orderedProperties;\n\t}\n\n\tprivate static void matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty) {\n\t\tif ( property != null ) {\n\t\t\tfinal String propertyAccessorName = property.getPropertyAccessorName();\n\t\t\tif ( !NOOP.getExternalName().equals( propertyAccessorName )","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java#L522-L558","documentation":"Error \"Referenced column '{}' mapped by target property '{}' occurs out of order in the list of '@JoinColumn's\" 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":["Reorder the @JoinColumn list so the referenced columns match the order of the columns of the referenced property."],"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"}