Skip to content

Commit 9934774

Browse files
committed
Use implicit join to create Predicate if possible
Fix spring-projectsGH-3349
1 parent fc8092d commit 9934774

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java

+14
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* @author Moritz Becker
5757
* @author Andrey Kovalev
5858
* @author Greg Turnquist
59+
* @author Yanming Zhou
5960
*/
6061
public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extends Object>, Predicate> {
6162

@@ -384,6 +385,19 @@ private Expression<? extends Comparable> getComparablePath(Root<?> root, Part pa
384385
}
385386

386387
private <T> Expression<T> getTypedPath(Root<?> root, Part part) {
388+
389+
// use implicit join if possible
390+
Path<?> path = root;
391+
PropertyPath property = part.getProperty();
392+
while (!property.isCollection()) {
393+
path = path.get(property.getSegment());
394+
if (property.hasNext()) {
395+
property = property.next();
396+
} else {
397+
return (Expression<T>) path;
398+
}
399+
}
400+
387401
return toExpressionRecursively(root, part.getProperty());
388402
}
389403

0 commit comments

Comments
 (0)