Fix regression in HQL parsing when primary alias is missing.

Original pull request: #3793
Closes #3792
This commit is contained in:
Christoph Strobl
2025-02-28 12:49:11 +01:00
committed by Mark Paluch
parent 668c335bc7
commit 7ea9391c43
2 changed files with 7 additions and 2 deletions

View File

@@ -100,8 +100,13 @@ class HqlCountQueryTransformer extends HqlQueryRenderer {
if (ctx.fromClause() != null) {
builder.appendExpression(visit(ctx.fromClause()));
if(primaryFromAlias == null) {
builder.append(TOKEN_AS);
builder.append(TOKEN_DOUBLE_UNDERSCORE);
}
}
if (ctx.whereClause() != null) {
builder.appendExpression(visit(ctx.whereClause()));
}

View File

@@ -919,11 +919,11 @@ class HqlQueryTransformerTests {
assertThat(alias("select u from User as u left join u.roles as r")).isEqualTo("u");
}
@Test // GH-2032
@Test // GH-2032, GH-3792
void countQueryShouldWorkEvenWithoutExplicitAlias() {
assertCountQuery("FROM BookError WHERE portal = :portal",
"select count(__) FROM BookError WHERE portal = :portal");
"select count(__) FROM BookError AS __ WHERE portal = :portal");
assertCountQuery("FROM BookError b WHERE portal = :portal",
"select count(b) FROM BookError b WHERE portal = :portal");