From 99347745176000785acee31014cea6ed4f1889e4 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Mon, 19 Feb 2024 16:50:12 +0800 Subject: [PATCH] Use implicit join to create Predicate if possible Fix GH-3349 --- .../data/jpa/repository/query/JpaQueryCreator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java index 255ac86dc3b..679529bbd7e 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java @@ -56,6 +56,7 @@ * @author Moritz Becker * @author Andrey Kovalev * @author Greg Turnquist + * @author Yanming Zhou */ public class JpaQueryCreator extends AbstractQueryCreator, Predicate> { @@ -384,6 +385,19 @@ private Expression getComparablePath(Root root, Part pa } private Expression getTypedPath(Root root, Part part) { + + // use implicit join if possible + Path path = root; + PropertyPath property = part.getProperty(); + while (!property.isCollection()) { + path = path.get(property.getSegment()); + if (property.hasNext()) { + property = property.next(); + } else { + return (Expression) path; + } + } + return toExpressionRecursively(root, part.getProperty()); }