Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented May 16, 2024

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.

https://hibernate.atlassian.net/browse/HHH-18026

…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.
@quaff
Copy link
Contributor Author

quaff commented May 16, 2024

@mbladel Please review.

Comment on lines +106 to +108
if ( modelPart.isEntityIdentifierMapping() ) {
// Default to the first position for entity identifiers
return 0;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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 calling columnIndex on an arbitrarily-ordered result set, without needing to ensure consistent id positions.

Yes, It's reasonable.

@mbladel
Copy link
Member

mbladel commented May 16, 2024

Thanks for proposing a solution. Closing this in favor of: #8391

@mbladel mbladel closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants