spring-data-jpa
spring-data-jpa copied to clipboard
`QueryUtils` does not detect alias of MERGE in native queries
As discovered in #2642 QueryUtils does not correctly detect the alias which is used in a merge statement.
Hence the following test case fails:
@Test
void queryUtilsDetectsMergeAliasCorrectly() {
String alias = QueryUtils.detectAlias(
"merge into a using (select id, value from b) query on (a.id = query.id) when matched then update set a.value = value");
assertThat(alias).isNotNull().isNotEmpty();
}
The test case fails because detectAlias(...) returns NULL instead of query.
We are working on a parsing solution to better handle such situations that QueryUtils accommodates. For the meantime, we are trying to avoid any more changes to QueryParser.
I'm dropping the query-parser label and revisit-after-query-rewrite label since this involves native queries.
Frankly, this situation appears too complicated for QueryUtils to handle, and we aren't likely to approve a change there that would meet your needs. Your best best moving forward may be to implement a custom implementation. Check out https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-implementations for more details on how to hook such a solution into your repository.