1515 */
1616package org .springframework .data .jpa .repository ;
1717
18- import static org .assertj .core .api .Assertions .* ;
18+ import static org .assertj .core .api .Assertions .assertThat ;
1919
2020import jakarta .persistence .EntityManager ;
2121import jakarta .persistence .criteria .CriteriaBuilder ;
2222import jakarta .persistence .criteria .CriteriaQuery ;
2323import jakarta .persistence .criteria .Predicate ;
2424import jakarta .persistence .criteria .Root ;
2525
26+ import java .util .List ;
27+
2628import org .junit .jupiter .api .AfterEach ;
2729import org .junit .jupiter .api .BeforeEach ;
2830import org .junit .jupiter .api .Test ;
2931import org .junit .jupiter .api .extension .ExtendWith ;
3032import org .springframework .beans .factory .annotation .Autowired ;
3133import org .springframework .data .domain .Example ;
34+ import org .springframework .data .domain .ExampleMatcher ;
3235import org .springframework .data .jpa .convert .QueryByExamplePredicateBuilder ;
3336import org .springframework .data .jpa .domain .sample .Role ;
37+ import org .springframework .data .jpa .domain .sample .User ;
3438import org .springframework .data .jpa .repository .sample .RoleRepository ;
39+ import org .springframework .data .jpa .repository .sample .UserRepository ;
3540import org .springframework .test .context .ContextConfiguration ;
3641import org .springframework .test .context .junit .jupiter .SpringExtension ;
3742import org .springframework .transaction .annotation .Transactional ;
3843
3944/**
4045 * @author Greg Turnquist
46+ * @author Christoph Strobl
4147 * @since 3.0
4248 */
4349@ ExtendWith (SpringExtension .class )
4450@ ContextConfiguration ({ "classpath:hibernate.xml" , "classpath:config/namespace-application-context.xml" })
4551@ Transactional
4652class QueryByExampleIntegrationTests {
4753
48- @ Autowired RoleRepository repository ;
54+ @ Autowired RoleRepository roleRepository ;
55+ @ Autowired UserRepository userRepository ;
4956 @ Autowired EntityManager em ;
5057
5158 private Role drummer ;
@@ -55,14 +62,14 @@ class QueryByExampleIntegrationTests {
5562 @ BeforeEach
5663 void setUp () {
5764
58- drummer = repository .save (new Role ("drummer" ));
59- guitarist = repository .save (new Role ("guitarist" ));
60- singer = repository .save (new Role ("singer" ));
65+ drummer = roleRepository .save (new Role ("drummer" ));
66+ guitarist = roleRepository .save (new Role ("guitarist" ));
67+ singer = roleRepository .save (new Role ("singer" ));
6168 }
6269
6370 @ AfterEach
6471 void clearUp () {
65- repository .deleteAll ();
72+ roleRepository .deleteAll ();
6673 }
6774
6875 @ Test // GH-2283
@@ -81,6 +88,39 @@ void queryByExampleWithNoPredicatesShouldHaveNoWhereClause() {
8188
8289 // then
8390 assertThat (predicate ).isNull ();
84- assertThat (repository .findAll (example )).containsExactlyInAnyOrder (drummer , guitarist , singer );
91+ assertThat (roleRepository .findAll (example )).containsExactlyInAnyOrder (drummer , guitarist , singer );
92+ }
93+
94+ @ Test // GH-3763
95+ void usesAnyMatchOnJoins () {
96+
97+ User manager = new User ("mighty" , "super user" , "msu@u.io" );
98+
99+ userRepository .save (manager );
100+
101+ User dave = new User ();
102+ dave .setFirstname ("dave" );
103+ dave .setLastname ("matthews" );
104+ dave .setEmailAddress ("d@dmb.com" );
105+ dave .addRole (singer );
106+
107+ User carter = new User ();
108+ carter .setFirstname ("carter" );
109+ carter .setLastname ("beaufort" );
110+ carter .setEmailAddress ("c@dmb.com" );
111+ carter .addRole (drummer );
112+ carter .addRole (singer );
113+ carter .setManager (manager );
114+
115+ userRepository .saveAllAndFlush (List .of (dave , carter ));
116+
117+ User probe = new User ();
118+ probe .setLastname (dave .getLastname ());
119+ probe .setManager (manager );
120+
121+ Example <User > example = Example .of (probe ,
122+ ExampleMatcher .matchingAny ().withIgnorePaths ("id" , "createdAt" , "age" , "active" , "emailAddress" ,
123+ "secondaryEmailAddress" , "colleagues" , "address" , "binaryData" , "attributes" , "dateOfBirth" ));
124+ assertThat (userRepository .findAll (example )).containsExactly (dave , carter );
85125 }
86126}
0 commit comments