Class SpringJtaSynchronizationAdapter
java.lang.Object
org.springframework.transaction.jta.SpringJtaSynchronizationAdapter
- All Implemented Interfaces:
jakarta.transaction.Synchronization
public class SpringJtaSynchronizationAdapter
extends Object
implements jakarta.transaction.Synchronization
Adapter that implements the JTA
Synchronization
interface delegating to an underlying Spring
TransactionSynchronization.
Useful for synchronizing Spring resource management code with plain JTA / EJB CMT transactions, despite the original code being built for Spring transaction synchronization.
- Since:
- 2.0
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization) Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization, @Nullable jakarta.transaction.TransactionManager jtaTransactionManager) Deprecated.SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization, @Nullable jakarta.transaction.UserTransaction jtaUserTransaction) Deprecated.as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown inbeforeCompletion, so the regularSpringJtaSynchronizationAdapter(TransactionSynchronization)constructor is sufficient for all scenarios -
Method Summary
Modifier and TypeMethodDescriptionvoidafterCompletion(int status) JTAafterCompletioncallback: invoked after commit/rollback.voidJTAbeforeCompletioncallback: just invoked before commit.
-
Field Details
-
logger
protected static final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
SpringJtaSynchronizationAdapter
Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.- Parameters:
springSynchronization- the Spring TransactionSynchronization to delegate to
-
SpringJtaSynchronizationAdapter
@Deprecated(since="6.0.12") public SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization, @Nullable jakarta.transaction.UserTransaction jtaUserTransaction) Deprecated.as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown inbeforeCompletion, so the regularSpringJtaSynchronizationAdapter(TransactionSynchronization)constructor is sufficient for all scenariosCreate a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.- Parameters:
springSynchronization- the Spring TransactionSynchronization to delegate tojtaUserTransaction- the JTA UserTransaction to use for rollback-only setting in case of an exception thrown inbeforeCompletion
-
SpringJtaSynchronizationAdapter
@Deprecated(since="6.0.12") public SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization, @Nullable jakarta.transaction.TransactionManager jtaTransactionManager) Deprecated.as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown inbeforeCompletion, so the regularSpringJtaSynchronizationAdapter(TransactionSynchronization)constructor is sufficient for all scenariosCreate a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.- Parameters:
springSynchronization- the Spring TransactionSynchronization to delegate tojtaTransactionManager- the JTA TransactionManager to use for rollback-only setting in case of an exception thrown inbeforeCompletion
-
-
Method Details
-
beforeCompletion
public void beforeCompletion()JTAbeforeCompletioncallback: just invoked before commit.In case of an exception, the JTA transaction will be marked as rollback-only.
- Specified by:
beforeCompletionin interfacejakarta.transaction.Synchronization- See Also:
-
afterCompletion
public void afterCompletion(int status) JTAafterCompletioncallback: invoked after commit/rollback.Needs to invoke the Spring synchronization's
beforeCompletionat this late stage in case of a rollback, since there is no corresponding callback with JTA.- Specified by:
afterCompletionin interfacejakarta.transaction.Synchronization- See Also:
-
beforeCompletion, so the regularSpringJtaSynchronizationAdapter(TransactionSynchronization)constructor is sufficient for all scenarios