DataSourceTransactionManager closes JDBC connection on doBegin failure but leaves it attached to transaction object [SPR-12280] #16885
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
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:
Affects: 3.2.11, 4.0.7, 4.1 GA
Issue Links:
Backported to: 4.0.8, 3.2.12
The text was updated successfully, but these errors were encountered: