Handle subqueries when used inside HQL INSERT statements.
Potentialy subqueries can crop up inside INSERT statements. We need to handle this as well. NOTE: INSERT statements aren't defined in JPQL, so this problem doesn't overlap with standard JPA queries. See #2977
This commit is contained in:
@@ -96,6 +96,8 @@ class HqlQueryTransformer extends HqlQueryRenderer {
|
||||
return true;
|
||||
} else if (ctx instanceof HqlParser.SelectStatementContext) {
|
||||
return false;
|
||||
} else if (ctx instanceof HqlParser.InsertStatementContext) {
|
||||
return false;
|
||||
} else {
|
||||
return isSubquery(ctx.getParent());
|
||||
}
|
||||
|
||||
@@ -973,6 +973,19 @@ class HqlQueryTransformerTests {
|
||||
.isEqualTo("FROM Story WHERE enabled = true order by created desc");
|
||||
}
|
||||
|
||||
@Test // GH-2977
|
||||
void isSubqueryThrowsException() {
|
||||
|
||||
String query = """
|
||||
insert into MyEntity (id, col)
|
||||
select max(id), col
|
||||
from MyEntityStaging
|
||||
group by col
|
||||
""";
|
||||
|
||||
assertThat(createQueryFor(query, Sort.unsorted())).isEqualToIgnoringWhitespace(query);
|
||||
}
|
||||
|
||||
private void assertCountQuery(String originalQuery, String countQuery) {
|
||||
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user