When 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. After that, when a proxy fires a load event, it opens a connection and performs the query, but the close() method is never invoked causing the connection to remain active in the pool and never be released. I have based my sample on projects of Hibernate repo. Following the example of hibernate-demo (cdi-jpa-testing) I made a sample project with Hibernate 5.4.2/5.4.3 using CDI and Spring Data JPA (that uses Spring AOP Proxies) test. After running into connection leaks with "Arjuna TransactionalDriver", I tried with "hibernate-agroal" but using a custom AgroalConnectionProvider (enabling transaction integration) with same result. |