Skip to content

Commit 2f591f5

Browse files
gregturnklajdipaja
authored andcommitted
Add additional tests to verify proper detection of alias values.
In the past, a token with "from" buried in it would trip up QueryUtils. These tests further demonstrate that this is no longer an issue with the HQL parser. Related: spring-projects#2508.
1 parent 0907c1c commit 2f591f5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,17 @@ void countQueryShouldWorkEvenWithoutExplicitAlias() {
808808
"select count(b) FROM BookError b WHERE portal = :portal");
809809
}
810810

811+
@Test // GH-2508
812+
void detectAliasWithCastCorrectly() {
813+
814+
assertThat(alias("from User u where (cast(:effective as date) is null) OR :effective >= u.createdAt"))
815+
.isEqualTo("u");
816+
assertThat(alias("from User u where (cast(:effectiveDate as date) is null) OR :effectiveDate >= u.createdAt"))
817+
.isEqualTo("u");
818+
assertThat(alias("from User u where (cast(:effectiveFrom as date) is null) OR :effectiveFrom >= u.createdAt"))
819+
.isEqualTo("u");
820+
}
821+
811822
private void assertCountQuery(String originalQuery, String countQuery) {
812823
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
813824
}

0 commit comments

Comments
 (0)