From 84ac0e8a85a9fc0b0f47fc45a45a8c90cf4ac6e8 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 12 May 2020 09:39:38 +0200 Subject: [PATCH] DATAMONGO-2542 - Shortcut PersistentPropertyPath resolution during query mapping. By shortcutting the path resolution we avoid checking keywords like $in against a potential path expression. Original pull request: #863. --- .../data/mongodb/core/convert/QueryMapper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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;