-
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-18026 Fix id column not found due to some driver doesn't follow JDBC specification #8390
Conversation
…DBC specification For example, MySQL mysql-connector-j driver use static `GENERATED_KEY` and MS SqlServer mssql-jdbc driver use static `GENERATED_KEYS` instead of actual column name. This commit will improve performance a bit also since it eliminate unnecessary column position lookup.
@mbladel Please review. |
if ( modelPart.isEntityIdentifierMapping() ) { | ||
// Default to the first position for entity identifiers | ||
return 0; |
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'm not sure this is safe, what if an identifier mapping is present in the result set but is not in the first position? Maybe for dialects that don't support returning arbitrary generated values it's fine, but there might be n
columns here and if we call columnIndex
it's because we can't ensure their order/position.
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.
Hibernate always and people used to create table using id column as first column, I think it's safe enough to assume that.
Anyway, this commit doesn't overturn the assumption you previous made, So It improved something but doesn't break anything.
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.
We should ensure id column is the first of columnNames
for inferredKeys=true
, I'm not sure it's already done by Hibernate.
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 think it might be at the moment, but I thought of a simpler solution: #8391
For dialects not supporting getGeneratedKeys
with custom column names the result set will always only contain 1 column: the identifier. This way we still leave the possibility of calling columnIndex
on an arbitrarily-ordered result set, without needing to ensure consistent id positions.
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.
For dialects not supporting
getGeneratedKeys
with custom column names the result set will always only contain 1 column: the identifier. This way we still leave the possibility of callingcolumnIndex
on an arbitrarily-ordered result set, without needing to ensure consistent id positions.
Yes, It's reasonable.
Thanks for proposing a solution. Closing this in favor of: #8391 |
For example, MySQL mysql-connector-j driver use static
GENERATED_KEY
and MS SqlServer mssql-jdbc driver use staticGENERATED_KEYS
instead of actual column name. This commit will improve performance a bit also since it eliminate unnecessary column position lookup.https://hibernate.atlassian.net/browse/HHH-18026