|
25 | 25 | import org.junit.jupiter.params.provider.Arguments;
|
26 | 26 | import org.junit.jupiter.params.provider.MethodSource;
|
27 | 27 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
| 28 | +import org.springframework.data.domain.PageRequest; |
28 | 29 | import org.springframework.data.domain.Sort;
|
29 | 30 | import org.springframework.data.jpa.domain.JpaSort;
|
30 | 31 | import org.springframework.lang.Nullable;
|
@@ -235,12 +236,12 @@ AND LOWER(COALESCE(vehicle.make, '')) LIKE :query)
|
235 | 236 | """)).isEqualTo("o");
|
236 | 237 | }
|
237 | 238 |
|
238 |
| - @Test // DATAJPA-252 |
| 239 | + @Test // DATAJPA-252, GH-664, GH-1066, GH-2960 |
239 | 240 | void doesNotPrefixOrderReferenceIfOuterJoinAliasDetected() {
|
240 | 241 |
|
241 | 242 | String query = "select p from Person p left join p.address address";
|
242 | 243 | Sort sort = Sort.by("address.city");
|
243 |
| - assertThat(createQueryFor(query, sort)).endsWith("order by p.address.city asc"); |
| 244 | + assertThat(createQueryFor(query, sort)).endsWith("order by address.city asc"); |
244 | 245 | }
|
245 | 246 |
|
246 | 247 | @Test // DATAJPA-252
|
@@ -742,6 +743,28 @@ where exists (
|
742 | 743 | """, relationshipName, joinAlias, joinAlias));
|
743 | 744 | }
|
744 | 745 |
|
| 746 | + @Test // GH-664, GH-1066, GH-2960 |
| 747 | + void sortingRecognizesJoinAliases() { |
| 748 | + |
| 749 | + String query = "select p from Customer c join c.productOrder p where p.delayed = true"; |
| 750 | + |
| 751 | + PageRequest page = PageRequest.of(0, 20, Sort.Direction.DESC, "lastName"); |
| 752 | + assertThat(createQueryFor(query, page.getSort())).isEqualToIgnoringWhitespace(""" |
| 753 | + select p from Customer c |
| 754 | + join c.productOrder p |
| 755 | + where p.delayed = true |
| 756 | + order by c.lastName desc |
| 757 | + """); |
| 758 | + |
| 759 | + PageRequest page2 = PageRequest.of(0, 20, Sort.Direction.DESC, "p.lineItems"); |
| 760 | + assertThat(createQueryFor(query, page2.getSort())).isEqualToIgnoringWhitespace(""" |
| 761 | + select p from Customer c |
| 762 | + join c.productOrder p |
| 763 | + where p.delayed = true |
| 764 | + order by p.lineItems desc |
| 765 | + """); |
| 766 | + } |
| 767 | + |
745 | 768 | static Stream<Arguments> queriesWithReservedWordsAsIdentifiers() {
|
746 | 769 |
|
747 | 770 | return Stream.of( //
|
|
0 commit comments