diff --git a/jdbc/src/main/java/org/springframework/transaction/TransactionManager.java b/jdbc/src/main/java/org/springframework/transaction/TransactionManager.java index 0023a6bc38..1cd21fd637 100644 --- a/jdbc/src/main/java/org/springframework/transaction/TransactionManager.java +++ b/jdbc/src/main/java/org/springframework/transaction/TransactionManager.java @@ -34,6 +34,7 @@ private T executeTransaction(Supplier transactionExecutor) { conn.setAutoCommit(false); result = transactionExecutor.get(); conn.commit(); + conn.setAutoCommit(true); } catch (final SQLException e) { rollBack(e, TransactionSynchronizationManager.getResource(dataSource)); } finally { @@ -42,9 +43,10 @@ private T executeTransaction(Supplier transactionExecutor) { return result; } - private void rollBack(final SQLException e, final Connection connection) { + private void rollBack(final SQLException e, final Connection conn) { try { - connection.rollback(); + conn.rollback(); + conn.setAutoCommit(true); throw new DataAccessException(e); } catch (final SQLException exception) { throw new DataAccessException(exception);