File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
main/java/org/springframework/data/jpa/repository/query
test/java/org/springframework/data/jpa/repository/query Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,29 @@ public List<JpaQueryParsingToken> visitFromRoot(HqlParser.FromRootContext ctx) {
276276 return tokens ;
277277 }
278278
279+ @ Override
280+ public List <JpaQueryParsingToken > visitJoin (HqlParser .JoinContext ctx ) {
281+
282+ List <JpaQueryParsingToken > tokens = new ArrayList <>();
283+
284+ tokens .addAll (visit (ctx .joinType ()));
285+ tokens .add (new JpaQueryParsingToken (ctx .JOIN ()));
286+
287+ if (!countQuery ) {
288+ if (ctx .FETCH () != null ) {
289+ tokens .add (new JpaQueryParsingToken (ctx .FETCH ()));
290+ }
291+ }
292+
293+ tokens .addAll (visit (ctx .joinTarget ()));
294+
295+ if (ctx .joinRestriction () != null ) {
296+ tokens .addAll (visit (ctx .joinRestriction ()));
297+ }
298+
299+ return tokens ;
300+ }
301+
279302 @ Override
280303 public List <JpaQueryParsingToken > visitAlias (HqlParser .AliasContext ctx ) {
281304
Original file line number Diff line number Diff line change @@ -903,6 +903,16 @@ void detectAliasWithCastCorrectly() {
903903 }
904904
905905
906+ @ Test // GH-2348
907+ void removeFetchFromJoinsDuringCountQueryCreation () {
908+
909+ assertCountQuery ("select u from User u left outer join fetch u.roles r left outer JOIN FETCH u.accounts a" ,
910+ "select count(u) from User u left outer join u.roles r left outer JOIN u.accounts a" );
911+
912+ assertCountQuery ("SELECT DISTINCT b FROM Board b LEFT JOIN FETCH b.comments ORDER BY b.id" ,
913+ "SELECT count(DISTINCT b) FROM Board b LEFT JOIN b.comments" );
914+ }
915+
906916 private void assertCountQuery (String originalQuery , String countQuery ) {
907917 assertThat (createCountQueryFor (originalQuery )).isEqualTo (countQuery );
908918 }
You can’t perform that action at this time.
0 commit comments