{"record":{"id":"8304ffad092d06a6","repo":"hibernate/hibernate-orm","slug":"passed-fieldresult-s-s-does-not-match-attribu","errorCode":null,"errorMessage":"Passed FieldResult [%s, %s] does not match AttributeFetchMapping [%s]","messagePattern":"Passed FieldResult \\[(.+?), (.+?)\\] does not match AttributeFetchMapping \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java","lineNumber":398,"sourceCode":"\t\tprivate final String[] propertyPathParts;\n\t\tprivate final List<String> columnNames;\n\n\t\tprivate AttributeFetchDescriptor(\n\t\t\t\tNavigablePath entityPath,\n\t\t\t\tString entityName,\n\t\t\t\tString propertyPath,\n\t\t\t\tString columnName) {\n\t\t\tthis.entityName = entityName;\n\t\t\tthis.propertyPath = propertyPath;\n\t\t\tpropertyPathParts = split( \".\", propertyPath );\n\t\t\tnavigablePath = entityPath;\n\t\t\tcolumnNames = new ArrayList<>();\n\t\t\tcolumnNames.add( columnName );\n\t\t}\n\n\t\tprivate void addColumn(FieldResult fieldResult) {\n\t\t\tif ( ! propertyPath.equals( fieldResult.name() ) ) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\t\"Passed FieldResult [%s, %s] does not match AttributeFetchMapping [%s]\",\n\t\t\t\t\t\t\t\tfieldResult.name(),\n\t\t\t\t\t\t\t\tfieldResult.column(),\n\t\t\t\t\t\t\t\tpropertyPath\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tcolumnNames.add( fieldResult.column() );\n\t\t}\n\n//\t\t@Override\n//\t\tpublic ResultMemento asResultMemento(NavigablePath path, ResultSetMappingResolutionContext resolutionContext) {\n//\t\t\tfinal EntityMappingType entityMapping =\n//\t\t\t\t\tresolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );\n//","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java#L380-L416","documentation":"When interpreting an @EntityResult's @FieldResult entries, Hibernate groups entries that target the same attribute into one AttributeFetchMapping and merges extra columns via addColumn(). addColumn() enforces the invariant that the incoming FieldResult's name() equals the group's propertyPath; a mismatch throws this IllegalArgumentException. In practice it fires when field-result entries that were assumed to target one attribute actually carry different property paths — typically inconsistent duplicates in the fields array.","triggerScenarios":"Duplicate @FieldResult entries for the same attribute where one uses a different name form (e.g. 'id' vs 'id.code' or a copy-paste of a sibling field's name) so the grouping logic hands addColumn() a non-matching path; annotation blocks duplicated during merges.","commonSituations":"Composite-id mappings where the same logical attribute is expressed once with a short name and once with a dotted path; copy-paste editing of @FieldResult lines; refactoring property names in only some of the duplicated entries.","solutions":["Inspect @EntityResult(fields = ...) for entries that claim the same columns and normalize them to one identical property-path spelling.","Remove leftover duplicate @FieldResult lines after copy-paste edits.","For composite keys, pick one convention (short name or full dotted path) and use it consistently for every column of that attribute."],"exampleFix":"// before: mixed name forms for the same target\n@EntityResult(entityClass = Order.class, fields = {\n    @FieldResult(name = \"id\", column = \"ORDER_ID1\"),\n    @FieldResult(name = \"id.code\", column = \"ORDER_ID2\")\n})\n\n// after: one consistent path per attribute\n@EntityResult(entityClass = Order.class, fields = {\n    @FieldResult(name = \"id.code\", column = \"ORDER_ID1\"),\n    @FieldResult(name = \"id.seq\", column = \"ORDER_ID2\")\n})","handlingStrategy":"validation","validationCode":"// before boot, check for inconsistent duplicate field results:\nMap<String, List<String>> columnsByName = new HashMap<>();\nfor ( FieldResult f : entityResult.fields() ) {\n    columnsByName.computeIfAbsent( f.name(), k -> new ArrayList<>() ).add( f.column() );\n}\n// duplicates are only legal when the name string is byte-identical;\n// flag entries sharing a first path segment but differing in full spelling, e.g. \"id\" vs \"id.code\"\nfor ( String name : columnsByName.keySet() ) {\n    for ( String other : columnsByName.keySet() ) {\n        if ( !name.equals( other ) && ( name.startsWith( other + \".\" ) || other.startsWith( name + \".\" ) ) ) {\n            throw new IllegalStateException( \"Inconsistent FieldResult name forms: '\" + name + \"' vs '\" + other + \"'\" );\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"catch ( IllegalArgumentException e ) {\n    if ( e.getMessage() != null && e.getMessage().startsWith( \"Passed FieldResult\" ) ) {\n        // message shows the mismatched name/column and expected path; normalize the duplicates in @EntityResult.fields\n    }\n}","preventionTips":["Use exactly one spelling (short or dotted) for each attribute across all its @FieldResult entries.","Run a duplicate-name scan over @FieldResult arrays after copy-paste edits.","Prefer @FieldResult once per column with a consistent naming convention for composite keys."],"tags":["hibernate","jpa","sql-result-set-mapping","field-result","annotations"],"backgroundTag":"field-result-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}