Skip to content

Commit fd69ee5

Browse files
committed
DataSourceTransactionManager resets ConnectionHolder on doBegin failure
Issue: SPR-12280
1 parent 05c995c commit fd69ee5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected Object doGetTransaction() {
179179
DataSourceTransactionObject txObject = new DataSourceTransactionObject();
180180
txObject.setSavepointAllowed(isNestedTransactionAllowed());
181181
ConnectionHolder conHolder =
182-
(ConnectionHolder) TransactionSynchronizationManager.getResource(this.dataSource);
182+
(ConnectionHolder) TransactionSynchronizationManager.getResource(this.dataSource);
183183
txObject.setConnectionHolder(conHolder, false);
184184
return txObject;
185185
}
@@ -238,7 +238,10 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
238238
}
239239

240240
catch (Throwable ex) {
241-
DataSourceUtils.releaseConnection(con, this.dataSource);
241+
if (txObject.isNewConnectionHolder()) {
242+
DataSourceUtils.releaseConnection(con, this.dataSource);
243+
txObject.setConnectionHolder(null, false);
244+
}
242245
throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
243246
}
244247
}

0 commit comments

Comments
 (0)