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

Infer database capabilities from JDBC-provided metadata on runtime init #13435

Merged
merged 2 commits into from
Nov 25, 2020

Conversation

yrodiere
Copy link
Member

Fixes #12412

Hibernate ORM has built-in support for interrogating the JDBC driver on startup in order to detect various low-level capabilities.

Among those capabilities: "getGeneratedKeys", the ability to send an insert command to a table with IDENTITY columns, and get in the result of that command the values generated by the database for these IDENTITY columns. This capability was not being detected properly, as reported in #12412.

The problem was simply that Quarkus, in an attempt to override the detection of the dialect, was also accidentally removing the code responsible for detecting database capabilities.

This restores that code while making sure we still override the detection of the dialect. The detection code, in case you are interested, is in org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator#initiateService.

The only drawback is an additional call to JdbcConnectionAccess.obtainConnection() on runtime init. As far as I can tell, since we always measure performance in terms of first response time anyway, and connections are pooled, this shouldn't significantly impact startup performance.

Note that "getGeneratedKeys" is not the only capability that Hibernate ORM tries to detect, so this patch may solve other, unreported problems caused by undetected database capabilities.

@DavideD @gavinking I believe Hibernate Reactive could take advantage of this metadata too, at least when a JDBC driver is available. And maybe there is equivalent metadata returned by reactive drivers. Anyway, I tried porting this fix to the Hibernate Reactive extensions, however I ran into problems in tests. It looks like the sequence-identity generator strategy is not supported yet in Hibernate Reactive, which ends up trying to increment a sequence when it should actually just let the database do it and retrieve the generated ID after an insert? I'll let you have a look if you are interested: https://github.com/yrodiere/quarkus/tree/i12412-reactive

@ghost ghost added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Nov 23, 2020
@yrodiere yrodiere requested a review from Sanne November 23, 2020 16:08
Signed-off-by: Yoann Rodière <yoann@hibernate.org>
Signed-off-by: Yoann Rodière <yoann@hibernate.org>
@gavinking
Copy link

I don't think Hibernate Reactive needs this because the Vert.x driver has a whole different API. And essentially among the 3 databases we support it's only relevant on MySQL so we just automatically use it with MySQL.

@Sanne
Copy link
Member

Sanne commented Nov 25, 2020

I think this is great, and might fix a couple more issues as side-effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hibernate.jdbc.use_get_generated_keys Support
3 participants