-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-12866 : apply "for update of" with aliases in Oracle dialect #2465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-12866 : apply "for update of" with aliases in Oracle dialect #2465
Conversation
|
@jedichenbin thanks for the PR! Do you know if there's a test really executing this type of query? Because we test how it is generated but we don't test if the query can be executed by Oracle AFAICS. |
|
@gsmet Good point. I've added a test (in the latest commit) to verify the query can be executed by Oracle. Please have a look and let me know your thoughts. Besides, there are a few existing tests which is related with locking, including Thank you. |
Inspired by the similar fix made in HHH-5654
08e326f to
cfb44be
Compare
|
@jedichenbin I made a couple of minor adjustments in your commits (mostly formatting but also some minor tuning), squashed some of them and force pushed to your branch. Could you get a fresh copy of your branch and rerun the test suite with Oracle? |
cfb44be to
056a995
Compare
|
@gsmet Thank you so much for reviewing and updating the commits. I thought the Travis build would run those tests against various databases, obviously I was wrong. Bad news - there are a few tests failed, including:
The root cause is that, these test cases were trying to create a query, apply a pagination, and also specify lock options. The generated SQL (see below) did not expose alias properly hence the -- Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "ABSTRACTSK0_"."ID": invalid identifier
select *
from (
select abstractsk0_.id as id1_0_,
abstractsk0_.processed as processed2_0_
from BatchJob abstractsk0_
)
where rownum <= :1
for update of abstractsk0_.id skip lockedI am working on a fix, which will pass down the |
|
The Travis build only runs the tests with H2. About locking and pagination, I recently removed the SQL 2008 limit handler as Oracle did not support for update with it: d85831f . I'm not sure there's a perfect solution for these limitations, especially when we don't have enough information to take the right decision in the dialects. |
We found a few test cases started to fail with previous commits. It's caused by a combination of pagination and lock options. Obviously in order to generate the SQL `for update of` it will needs to put table alias. However, when the code is using `setMaxResults` to do pagination, internally Oracle dialects will call `LIMIT_HANDLER` to generate extra bits in the SQL which uses `rownum`. Now, because it wraps the original SQL, none of the table aliases will be exposed. Hence eventually the generated SQL got rejected by Oracle due to ORA-00904 (invalid identifier). This fix is to only apply `for update of` when it's really necessary. Thanks to `QueryLoader.applyLocks()` where it actually adds all the `sqlAlias` with `effectiveLockMode` to the `LockOptions`. We could compare the tables to determine whether it's *necessary* to add that `of [tableAlias].[column]` part.
|
@gsmet - thanks for the clarification about the Travis builds. Apologise for my naive assumptions. Just curious - is there any other CI which is configured to run the tests, which are annotated with About that commit related with HHH-12848 - yes, I noticed that commit yesterday. It looks good because according to Oracle 12c document one of the restrictions of using
So without that commit the I've pushed a commit that fixes all the failed tests mentioned in my previous |
|
@gsmet I have both Oracle 11g and 12c installed on my machine. Would you like me to test and validate this? If it works, I could integrate it to master and 5.3 if you want. |
|
Thanks for your pull request! This pull request does not follow the contribution rules. Could you have a look? ❌ All commit messages should start with a JIRA issue key matching pattern › This message was automatically generated. |
|
superseded by #9330 |
Similar to the issue HHH-5654, which had been fixed in
PostgreSql81Dialect, when lock mode was specified with an alias, the generated SQL for Oracle database is not using the alias at all.According to Oracle's documentation of for-update clause, the syntax allows user to specify "table.column" in order to lock the select rows only for a particular table or view in a join.
Tests have been added for Oracle dialects including 8i, 9i, 10g, and 12c. The fix is only in
Oracle8iDialectas all the other dialects extends from this one.Please refer to the description of JIRA ticket HHH-12866.