diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index 884446cf8..6434021e5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -965,7 +965,7 @@ public class QueryMapper { this.entity = entity; this.mappingContext = context; - this.path = getPath(removePlaceholders(POSITIONAL_PARAMETER_PATTERN, name)); + this.path = getPath(removePlaceholders(POSITIONAL_PARAMETER_PATTERN, name), property); this.property = path == null ? property : path.getLeafProperty(); this.association = findAssociation(); } @@ -1079,11 +1079,17 @@ public class QueryMapper { * @return */ @Nullable - private PersistentPropertyPath getPath(String pathExpression) { + private PersistentPropertyPath getPath(String pathExpression, + MongoPersistentProperty sourceProperty) { String rawPath = removePlaceholders(POSITIONAL_OPERATOR, removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression)); + if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) { + return mappingContext + .getPersistentPropertyPath(PropertyPath.from(sourceProperty.getName(), entity.getTypeInformation())); + } + PropertyPath path = forName(rawPath); if (path == null || isPathToJavaLangClassProperty(path)) { return null;