Performance degradation after upgrading Hibernate from 6 to 7 cause of early acquisition of physical connection

Hi all!

I discovered that my application’s performance had degraded by about 15% after 6->7 upgrade. After some investigation, I found the cause: early acquisition of physical connection for each SELECT query.

JdbcSelectExecutorStandardImpl.java#L132

I propose optimizing this method.

Acquire the connection only when both conditions are met:

  1. jdbcSelect instance of JdbcSelectWithActions
  2. The set of pre and post actions is not empty

Is it possible to discuss this improvement? I can provide a test case if needed.

Sure, please provide a test case and explain what you found during your analysis.

I have a wrapper around the connection that sets its name via a SQL query (PostgreSQL):

select 1 from set_config('application_name',?, false)

This query is executed every time a connection is opened. Compared to version 6, the number of SELECT queries has increased several-fold (and total execution time).

Hibernate 6:

Hibernate 7:

And the connection opens even with a fast query cache. The presence of a connection pool has no effect on the result (using Hikari).

I don’t know how to attach test case here as file (probably can to jira).

Thanks for the insight. The increase of the query count is unfortunate, but can have many reasons. Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.