1818import jakarta .persistence .criteria .CriteriaBuilder ;
1919import jakarta .persistence .criteria .Expression ;
2020import jakarta .persistence .criteria .From ;
21+ import jakarta .persistence .criteria .JoinType ;
2122import jakarta .persistence .criteria .Path ;
2223import jakarta .persistence .criteria .Predicate ;
2324import jakarta .persistence .criteria .Root ;
5758 * @author Oliver Gierke
5859 * @author Jens Schauder
5960 * @author Greg Turnquist
61+ * @author Arnaud Lecointre
6062 * @since 1.10
6163 */
6264public class QueryByExamplePredicateBuilder {
@@ -103,7 +105,8 @@ public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Examp
103105 ExampleMatcher matcher = example .getMatcher ();
104106
105107 List <Predicate > predicates = getPredicates ("" , cb , root , root .getModel (), example .getProbe (),
106- example .getProbeType (), new ExampleMatcherAccessor (matcher ), new PathNode ("root" , null , example .getProbe ()),
108+ example .getProbeType (), matcher , new ExampleMatcherAccessor (matcher ),
109+ new PathNode ("root" , null , example .getProbe ()),
107110 escapeCharacter );
108111
109112 if (predicates .isEmpty ()) {
@@ -121,7 +124,7 @@ public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Examp
121124
122125 @ SuppressWarnings ({ "rawtypes" , "unchecked" })
123126 static List <Predicate > getPredicates (String path , CriteriaBuilder cb , Path <?> from , ManagedType <?> type , Object value ,
124- Class <?> probeType , ExampleMatcherAccessor exampleAccessor , PathNode currentNode ,
127+ Class <?> probeType , ExampleMatcher matcher , ExampleMatcherAccessor exampleAccessor , PathNode currentNode ,
125128 EscapeCharacter escapeCharacter ) {
126129
127130 List <Predicate > predicates = new ArrayList <>();
@@ -158,7 +161,7 @@ static List<Predicate> getPredicates(String path, CriteriaBuilder cb, Path<?> fr
158161
159162 predicates
160163 .addAll (getPredicates (currentPath , cb , from .get (attribute .getName ()), (ManagedType <?>) attribute .getType (),
161- attributeValue , probeType , exampleAccessor , currentNode , escapeCharacter ));
164+ attributeValue , probeType , matcher , exampleAccessor , currentNode , escapeCharacter ));
162165 continue ;
163166 }
164167
@@ -171,8 +174,10 @@ static List<Predicate> getPredicates(String path, CriteriaBuilder cb, Path<?> fr
171174 ClassUtils .getShortName (probeType ), node ));
172175 }
173176
174- predicates .addAll (getPredicates (currentPath , cb , ((From <?, ?>) from ).join (attribute .getName ()),
175- (ManagedType <?>) attribute .getType (), attributeValue , probeType , exampleAccessor , node , escapeCharacter ));
177+ JoinType joinType = matcher .isAllMatching () ? JoinType .INNER : JoinType .LEFT ;
178+ predicates .addAll (getPredicates (currentPath , cb , ((From <?, ?>) from ).join (attribute .getName (), joinType ),
179+ (ManagedType <?>) attribute .getType (), attributeValue , probeType , matcher , exampleAccessor , node ,
180+ escapeCharacter ));
176181
177182 continue ;
178183 }
0 commit comments