Hello, I would like to ask about the connection closure strategy during the lazy loading of references.
I have a test project with Hibernete 5.4 + JPA + JTA + CDI + Agroal, and I’m having a connection leakage problem (github test project).
When the entityManager.getReference () method is invoked, the transaction interceptor @Transactional is executed and the commit is done but at this moment without involving any connection to the database.
Then, when a proxy activates a load event, it opens a connection and performs the query, but the connection is never returned to the connection pool (the connection close() method is never invoked).
I tried using the close strategy at the end of the transaction and tried using the close strategy at the end of the statement, however neither of the tests convince me.
The strategy of closing connections with the statement impacts performance and shows a strange metrics in the “Agroal” pool (acquires more connections than it returns).
And the desired strategy of closing connections at the end of the transaction has the problem of occupying more physical resources and perhaps ending up in a connection leak.
The questions are:
where is Hibernate supposed to close the requested connections for the lazy load of the entity?
Should It not request a connection with “autoCommit = true” and close the connection after recovering the entity?
Is the “delayedAfterCompletion()” method where it should be invoked?
Otherwise, are they expected to close when the entity manager closes (using physical resources in the meantime)?
Thanks