Skip to content

Commit 1d69ece

Browse files
committed
Verify proper sort handling even if HQL query already has ORDER BY a native function.
Introduce test case proving that apply a Sort to an HQL query with an already-existing "order by function()" is handled properly. Resolves #2862.
1 parent 6e389d7 commit 1d69ece

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/HqlQueryTransformerTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,15 @@ void orderByShouldWorkWithSubSelectStatements() {
784784
+ "from foo f", sort)).endsWith("order by f.age desc");
785785
}
786786

787+
@Test // GH-2862
788+
void sortProperlyAppendsToExistingOrderByWithFunction() {
789+
790+
assertThat(createQueryFor(
791+
"select e from SampleEntity e where function('nativeFunc', ?1) > 'testVal' order by function('nativeFunc', ?1)",
792+
Sort.by(Sort.Order.desc("age")))).isEqualTo(
793+
"select e from SampleEntity e where function('nativeFunc', ?1) > 'testVal' order by function('nativeFunc', ?1), e.age desc");
794+
}
795+
787796
private void assertCountQuery(String originalQuery, String countQuery) {
788797
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
789798
}

0 commit comments

Comments
 (0)