Affects: Spring Framework 5.2.9.RELEASE, Hibernate 5.4.21.Final
Suspected connection leak in Spring Hibernation 5 integration with using JTA transaction manager.
Consider the following sample application context XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<context:component-scan
base-package="com.github.sammyhk.test" />
<tx:annotation-driven
transaction-manager="transactionManager" mode="proxy"
proxy-target-class="false" />
<!-- Wildfly managed data source -->
<jee:jndi-lookup id="dataSource"
jndi-name="java:jboss/datasources/testDataSource"
expected-type="javax.sql.DataSource" resource-ref="true" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value><![CDATA[com.github.sammyhk.test.MyEntity]]></value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"><![CDATA[org.hibernate.dialect.Oracle10gDialect]]></prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager" />
<!-- Using Hibernate Template to CRUD MyEntity -->
<bean id="myEntityDao" class="com.github.sammyhk.test.MyEntityDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Annotated with @org.springframework.transaction.annotation.Transactional, operate myEntityDao in a transaction -->
<bean id="myService" class="com.github.sammyhk.test.MyServiceImpl">
<property name="myEntityDao" ref="myEntityDao" />
</bean>
</beans>
Calling myService will be suspected connection leak due to Hibernate session has NOT been close. Debugging found org.springframework.orm.hibernate5.SpringSessionSynchronization has NOT been registered due to org.springframework.orm.hibernate5.SpringSessionContext returned at line 122 while SpringSessionSynchronization registration is in line 136.
In this example we tried to use HibernateTransactionManager and it is working correctly, but using JtaTransactionManager encountered such issue.
Affects: Spring Framework 5.2.9.RELEASE, Hibernate 5.4.21.Final
Suspected connection leak in Spring Hibernation 5 integration with using JTA transaction manager.
Consider the following sample application context XML:
Calling myService will be suspected connection leak due to Hibernate session has NOT been close. Debugging found
org.springframework.orm.hibernate5.SpringSessionSynchronizationhas NOT been registered due toorg.springframework.orm.hibernate5.SpringSessionContextreturned at line 122 whileSpringSessionSynchronizationregistration is in line 136.In this example we tried to use
HibernateTransactionManagerand it is working correctly, but usingJtaTransactionManagerencountered such issue.