diff --git a/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java b/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java index 8cfc28e4a6..621bbae614 100644 --- a/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java +++ b/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java @@ -32,7 +32,7 @@ public static Connection unbindResource(final DataSource key) { public static boolean isTransactionActive(final DataSource dataSource) { try { - return resources.get().get(dataSource).getAutoCommit(); + return !resources.get().get(dataSource).getAutoCommit(); } catch (final SQLException e) { throw new TransactionSynchronizationManagerException(e); } diff --git a/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java b/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java index 1cae78ae81..cc9234f27e 100644 --- a/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java +++ b/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java @@ -65,15 +65,24 @@ class IsTransactionActive { @DisplayName("실행한 경우") void trueCase() throws SQLException { final DataSource datasource = getInstance(); - TransactionSynchronizationManager.bindResource(datasource, datasource.getConnection()); + final Connection connection = datasource.getConnection(); + connection.setAutoCommit(false); + + TransactionSynchronizationManager.bindResource(datasource, connection); assertTrue(isTransactionActive(getInstance())); + connection.close(); } @Test @DisplayName("실행하지 않은 경우") void falseCase() throws SQLException { + final DataSource datasource = getInstance(); + final Connection connection = datasource.getConnection(); + TransactionSynchronizationManager.bindResource(datasource, connection); + assertFalse(isTransactionActive(getInstance())); + connection.close(); } }