Skip to content

Commit 7ea9391

Browse files
christophstroblmp911de
authored andcommitted
Fix regression in HQL parsing when primary alias is missing.
Original pull request: #3793 Closes #3792
1 parent 668c335 commit 7ea9391

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlCountQueryTransformer.java

+5
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ public QueryRendererBuilder visitFromQuery(HqlParser.FromQueryContext ctx) {
100100

101101
if (ctx.fromClause() != null) {
102102
builder.appendExpression(visit(ctx.fromClause()));
103+
if(primaryFromAlias == null) {
104+
builder.append(TOKEN_AS);
105+
builder.append(TOKEN_DOUBLE_UNDERSCORE);
106+
}
103107
}
104108

109+
105110
if (ctx.whereClause() != null) {
106111
builder.appendExpression(visit(ctx.whereClause()));
107112
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,11 @@ void queryParserPicksCorrectAliasAmidstMultipleAlises() {
919919
assertThat(alias("select u from User as u left join u.roles as r")).isEqualTo("u");
920920
}
921921

922-
@Test // GH-2032
922+
@Test // GH-2032, GH-3792
923923
void countQueryShouldWorkEvenWithoutExplicitAlias() {
924924

925925
assertCountQuery("FROM BookError WHERE portal = :portal",
926-
"select count(__) FROM BookError WHERE portal = :portal");
926+
"select count(__) FROM BookError AS __ WHERE portal = :portal");
927927

928928
assertCountQuery("FROM BookError b WHERE portal = :portal",
929929
"select count(b) FROM BookError b WHERE portal = :portal");

0 commit comments

Comments
 (0)