I have a pretty large transaction, annotated with @Transactional
. There are a few long-running queries in it, but usually runs fine. About 20% of the time the Connection
appears to be getting forcibly closed outside of the transaction, and when the transaction tries to continue doing work, it fails with the following stack trace. Even worse, the transaction is not rolling back.
JDBC commits by default on connection close. However, Spring should be setting the Connection's auto-commit to false using something like the following before opening the transaction (Spring @Transactional and JDBC autoCommit). I've confirmed that the version we are using still does this. We use SimpleJdbcTemplate
to execute the queries and the connections are obtained from an Apache Commons DBCP
pool.
Is this an issue where DBCP thinks the connection is stale (as the transaction has a few long-running queries in it) and so the pool tries to reclaim the connection, committing it along the way? Shouldn't autocommit=false prevent this? Anyone have any other suggestions?
Thanks
Using (All pretty old):
SpringJDBC 2.5
Oracle JDBC Drivers 11.1.0.7 (ojdbc6)
Apache Commons DBCP 1.2.1
Stack trace:
Activity threw exception:
org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is java.sql.SQLException: Connection oracle.jdbc.driver.T4CConnection@56a2191a is closed.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:279)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:800)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:777)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:339)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
[...]
Caused by: java.sql.SQLException: Connection oracle.jdbc.driver.T4CConnection@56a2191a is closed.
at org.apache.commons.dbcp.DelegatingConnection.checkOpen(DelegatingConnection.java:398)
at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:276)
... 21 more