Infer database capabilities from JDBC-provided metadata on runtime init #13435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theseIDENTITY
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