Skip to content

Commit 2f6955e

Browse files
committed
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: #2508.
1 parent efc9aed commit 2f6955e

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

Lines changed: 11 additions & 0 deletions
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)