Description
Simon Kitching opened SPR-12280 and commented
DataSourceTransactionManager.doBegin first allocates a connection from the datasource and stores it in the DataSourceTransactionObject. It then does some other work; if any of this other work throws an exception then that connection is released but is not removed from the DataSourceTransactionObject. The result is a misleading "java.sql.SQLException: Connection is closed" exception later.
This problem is present in current trunk code, and at least as far back as 3.0.7 (the version I'm using):
In my particular case, this line in DataSourceTransactionManager.doBegin is throwing an exception:
Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
which causes the catch clause in the same method to run.
Of course if I resolve the initial problem that causes prepareConnectionForTransaction to fail ("SET TRANSACTION must be first statement of transaction" on oracle), then this issue will no longer occur. However the presence of misleading "connection closed" errors makes diagnosis of the real problem more difficult..
This problem seems similar to/related to the following existing issues:
- JDBC Connection is not released due to incorrectly defined catch [SPR-10755] #15381
- Restoring previous isolation level causes side effects on Oracle [SPR-2090] #6783
- LDAP-179
Affects: 3.2.11, 4.0.7, 4.1 GA
Issue Links:
- JDBC Connection is not released due to incorrectly defined catch [SPR-10755] #15381 JDBC Connection is not released due to incorrectly defined catch