-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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-12492 Jpa DELETE Query generated has missing table alias and thus incorrect semantics #2439
Conversation
…t query's aliases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one minor comment.
@@ -172,7 +172,7 @@ public String getClassAlias() { | |||
//return classAlias == null ? className : classAlias; | |||
} | |||
|
|||
private String getTableName() { | |||
public String getTableName() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I removed that.
…ueries in DELETE/UPDATE queries Don't try to duplicate the logic from org.hibernate.hql.internal.ast.tree.FromElementType#toColumns(java.lang.String, java.lang.String, boolean, boolean) in other classes, it's complex enough and already seems to handle all the cases we might encounter. In this specific case, we want the table name to be used to qualify column names, because the target table doesn't have any alias (it's not supported by every version of every RDBMS), and not qualifying columns at all may lead to a confusing statement, in particular if tables referenced in the subquery contain columns with the same name. Since we use aliases for every other table in the query, referencing the table should not lead to any conflict.
@@ -197,14 +197,6 @@ private boolean resolveAsAlias() { | |||
|
|||
String[] columnExpressions = element.getIdentityColumns(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the general idea is to fix this getIdentityColumns()
to avoid needing the workaround below.
This is done by using an existing logic doing exactly what we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Also, getIdentityColumns
is only used in IdentNode#resolveAsAlias
, so changing its behavior should not affect any other node or any other resolution of an IdentNode
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some scrolling through the related code, and having played with FromElement
recently, I can confirm that the replaced code in getIdentityColumns()
was indeed a simplified version of what happened in the toColumns
function now. The latter indeed has a special handling for subqueries. This change looks good to me!
I'm not familiar enough with this code to know for sure. @dreab8, can you take a look? |
The PR looks fine to me just not 100% sure the change to the
this seems enough to solve the issue. |
@dreab8 keep in mind that hte change in @yrodiere can you think of a case where keeping the code in |
…in subqueries in DELETE/UPDATE queries
I also think it's confusing and just wrong to keep this piece of code. But I doubt it will ever get executed, so I guess in this regard it's "safer" to keep it. I pushed a fix-up commit that restores this piece of code, let's see if any test fails. |
I haven't checked the details of the PR or specific DBMS, I just wanted to mention that I think this was done this way because some DBMS do not support an explicit alias for DML tables and instead require the use of the table name. |
This.
…On Thu, Jul 26, 2018, 7:52 AM Christian Beikov ***@***.***> wrote:
I haven't checked the details of the PR or specific DBMS, I just wanted to
mention that I think this was done this way because some DBMS do not
support an explicit alias for DML tables and instead require the use of the
table name.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2439 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOUE0UAe0wWr8ncs2WP6tSwIyS2PvxTks5uKbtygaJpZM4VV47L>
.
|
Yes, this was accounted for. |
To be clearer: |
Merged, thanks! |
https://hibernate.atlassian.net//browse/HHH-12492
Given the very sensitive section of the code I had to change, maybe we should wait for 5.4 before merging this. That being said, my first attempt was definitely buggy and at least 3 previously existing tests failed as a result, which is reassuring.