diff --git a/CHANGELOG.md b/CHANGELOG.md index 43840b7..39bf163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.13.0] - 2024-02-13 + +### Added + +* `TransactionHelper` only attempts to rollback if the transaction was created by the helper. + ## [1.12.3] - 2024-01-11 ### Fixed diff --git a/gradle.properties b/gradle.properties index f71e84b..ef52e60 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.12.3 \ No newline at end of file +version=1.13.0 \ No newline at end of file diff --git a/tw-base-utils/src/main/java/com/transferwise/common/baseutils/transactionsmanagement/TransactionsHelper.java b/tw-base-utils/src/main/java/com/transferwise/common/baseutils/transactionsmanagement/TransactionsHelper.java index f16a66c..0fbf6b7 100644 --- a/tw-base-utils/src/main/java/com/transferwise/common/baseutils/transactionsmanagement/TransactionsHelper.java +++ b/tw-base-utils/src/main/java/com/transferwise/common/baseutils/transactionsmanagement/TransactionsHelper.java @@ -106,14 +106,17 @@ public T call(Callable callable) { } TransactionStatus status = transactionManager.getTransaction(def); + boolean newTransaction = status.isNewTransaction(); T result; try { result = callable.call(); } catch (Throwable t) { - try { - transactionManager.rollback(status); - } catch (Throwable t2) { - log.error("Failed to rollback transaction '{}' ({}).", name != null ? name : "", def, t2); + if (newTransaction) { + try { + transactionManager.rollback(status); + } catch (Throwable t2) { + log.error("Failed to rollback transaction '{}' ({}).", name != null ? name : "", def, t2); + } } throw t; }