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

**URL:** <https://discourse.hibernate.org/t/performance-degradation-after-upgrading-hibernate-from-6-to-7-cause-of-early-acquisition-of-physical-connection/12422>\
**Category:** Hibernate ORM\
**Created:** [September 7, 2026, 7:53am UTC](https://discourse.hibernate.org/t/performance-degradation-after-upgrading-hibernate-from-6-to-7-cause-of-early-acquisition-of-physical-connection/12422 "2026-09-07T07:53:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![art.kobelev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/art.kobelev/32/3383_2.png) [@art.kobelev](https://discourse.hibernate.org/u/art.kobelev)\
**Post date:** [September 7, 2026, 7:53am UTC](https://discourse.hibernate.org/t/performance-degradation-after-upgrading-hibernate-from-6-to-7-cause-of-early-acquisition-of-physical-connection/12422/1 "2026-09-07T07:53:20Z")

</div>

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](https://github.com/hibernate/hibernate-orm/blob/7.4.7/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 7, 2026, 11:04am UTC](https://discourse.hibernate.org/t/performance-degradation-after-upgrading-hibernate-from-6-to-7-cause-of-early-acquisition-of-physical-connection/12422/2 "2026-09-07T11:04:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![art.kobelev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/art.kobelev/32/3383_2.png) [@art.kobelev](https://discourse.hibernate.org/u/art.kobelev)\
**Post date:** [September 7, 2026, 11:58am UTC](https://discourse.hibernate.org/t/performance-degradation-after-upgrading-hibernate-from-6-to-7-cause-of-early-acquisition-of-physical-connection/12422/3 "2026-09-07T11:58:52Z")

</div>

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:

 ![hib6](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/5/592055e0dab64ca220cbedcc3af7907a0772df76.png)

Hibernate 7:

 ![hib7](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/8/8e4b394347229e0746f031b960a0cc10b0168d8f.png)

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).

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 7, 2026, 3:59pm UTC](https://discourse.hibernate.org/t/performance-degradation-after-upgrading-hibernate-from-6-to-7-cause-of-early-acquisition-of-physical-connection/12422/4 "2026-09-07T15:59:37Z")

</div>

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](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and if you are able to reproduce the issue, create a bug ticket in our [issue tracker](https://hibernate.atlassian.net) and attach that reproducer.
