hibernate/hibernate-orm · error · IllegalArgumentException
Passed FieldResult [%s, %s] does not match AttributeFetchMap
Error message
Passed FieldResult [%s, %s] does not match AttributeFetchMapping [%s]
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java:398
private final String[] propertyPathParts;
private final List<String> columnNames;
private AttributeFetchDescriptor(
NavigablePath entityPath,
String entityName,
String propertyPath,
String columnName) {
this.entityName = entityName;
this.propertyPath = propertyPath;
propertyPathParts = split( ".", propertyPath );
navigablePath = entityPath;
columnNames = new ArrayList<>();
columnNames.add( columnName );
}
private void addColumn(FieldResult fieldResult) {
if ( ! propertyPath.equals( fieldResult.name() ) ) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"Passed FieldResult [%s, %s] does not match AttributeFetchMapping [%s]",
fieldResult.name(),
fieldResult.column(),
propertyPath
)
);
}
columnNames.add( fieldResult.column() );
}
// @Override
// public ResultMemento asResultMemento(NavigablePath path, ResultSetMappingResolutionContext resolutionContext) {
// final EntityMappingType entityMapping =
// resolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );
//View on GitHub (pinned to fad1729dce)
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.
Example fix
// before: mixed name forms for the same target
@EntityResult(entityClass = Order.class, fields = {
@FieldResult(name = "id", column = "ORDER_ID1"),
@FieldResult(name = "id.code", column = "ORDER_ID2")
})
// after: one consistent path per attribute
@EntityResult(entityClass = Order.class, fields = {
@FieldResult(name = "id.code", column = "ORDER_ID1"),
@FieldResult(name = "id.seq", column = "ORDER_ID2")
}) Defensive patterns
Strategy: validation
Validate before calling
// before boot, check for inconsistent duplicate field results:
Map<String, List<String>> columnsByName = new HashMap<>();
for ( FieldResult f : entityResult.fields() ) {
columnsByName.computeIfAbsent( f.name(), k -> new ArrayList<>() ).add( f.column() );
}
// duplicates are only legal when the name string is byte-identical;
// flag entries sharing a first path segment but differing in full spelling, e.g. "id" vs "id.code"
for ( String name : columnsByName.keySet() ) {
for ( String other : columnsByName.keySet() ) {
if ( !name.equals( other ) && ( name.startsWith( other + "." ) || other.startsWith( name + "." ) ) ) {
throw new IllegalStateException( "Inconsistent FieldResult name forms: '" + name + "' vs '" + other + "'" );
}
}
} Try / catch
catch ( IllegalArgumentException e ) {
if ( e.getMessage() != null && e.getMessage().startsWith( "Passed FieldResult" ) ) {
// message shows the mismatched name/column and expected path; normalize the duplicates in @EntityResult.fields
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ConstructorResult did not define any ColumnResults
- Non-terminal property path did not reference FetchableContai
- Class '<componentClassName>' is an '@Embeddable' type and ma
- Property '<propertyName>' may not be annotated '@BatchSize'
- One to many association '<propertyName>' was annotated '@Col
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/8304ffad092d06a6.
Report an issue: GitHub.