Skip to content

Commit cd82d50

Browse files
mp911dechristophstrobl
authored andcommitted
Deprecate ChainedTransactionManager.
We recommend to not use ChainedTransactionManager as it emulates distributed transactions without providing consistency guarantees that can end up in partially committed transactions. To attach to commit/rollback operations we recommend registering TransactionSynchronization instead. Closes #2232 Original Pull Request: #2286
1 parent fe5a8f4 commit cd82d50

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/main/java/org/springframework/data/transaction/ChainedTransactionManager.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,32 @@
4444
* which means the {@link PlatformTransactionManager} most likely to break the transaction should be the <em>last</em>
4545
* in the list configured. A {@link PlatformTransactionManager} throwing an exception during commit will automatically
4646
* cause the remaining transaction managers to roll back instead of committing.
47+
* <p />
48+
* As consequence, a transaction can get into a state, where the first {@link PlatformTransactionManager} has committed
49+
* its transaction and a subsequent {@link PlatformTransactionManager} failed to commit its transaction (e.g. caused by
50+
* an I/O error or the transactional resource failed to commit for other reasons). In that case,
51+
* {@link #commit(TransactionStatus)} throws a {@link HeuristicCompletionException} to indicate a partially committed
52+
* transaction. Rollback isn't affected as the natural consequence of a missing commit is a rollback of a transactional
53+
* resource. {@link ChainedTransactionManager} should be only used if the application can tolerate or recover from
54+
* inconsistent state caused by partially committed transactions. In any other case, the use of
55+
* {@link ChainedTransactionManager} is not recommended.
56+
* <p/>
57+
* Instead of using {@link ChainedTransactionManager} for attaching callbacks to transaction commit (pre commit/post
58+
* commit), either register a {@link org.springframework.transaction.reactive.TransactionSynchronization} to explicitly
59+
* follow transaction cleanup with simplified semantics in case of exceptions.
4760
*
4861
* @author Michael Hunger
4962
* @author Oliver Gierke
63+
* @author Mark Paluch
5064
* @since 1.6
65+
* @see org.springframework.transaction.support.TransactionSynchronization#beforeCommit(boolean)
66+
* @see org.springframework.transaction.support.TransactionSynchronization#afterCommit()
67+
* @deprecated since 2.5
5168
*/
69+
@Deprecated
5270
public class ChainedTransactionManager implements PlatformTransactionManager {
5371

54-
private final static Log logger = LogFactory.getLog(ChainedTransactionManager.class);
72+
private final static Log logger = LogFactory.getLog(ChainedTransactionManager.class);
5573

5674
private final List<PlatformTransactionManager> transactionManagers;
5775
private final SynchronizationManager synchronizationManager;
@@ -156,7 +174,7 @@ public void commit(TransactionStatus status) throws TransactionException {
156174

157175
} else {
158176

159-
// after unsucessfull commit we must try to rollback remaining transaction managers
177+
// after unsuccessful commit we must try to rollback remaining transaction managers
160178

161179
try {
162180
multiTransactionStatus.rollback(transactionManager);

0 commit comments

Comments
 (0)