How to get Spring Transaction Manager instance?

I use annotations to mark the methods that should be executed in a transaction.

But in one place I need to do it transactionManager.rollback()manually, without annotation. How can I get an object transactionManager?

+3
source share
2 answers

If you want to cancel the current transaction, you can use

    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

Please note that it does not roll back the transaction immediately - it sets the status to "rollback only", so the transaction will be rolled back during a commit attempt.


Otherwise, if you need demarcation of software transactions, you can use TransactionTemplate, as described in 10.6 Software Transaction Management .

You can also get an instance PlatformTransactionManager, but it is not widely used, since it TransactionTemplateis the recommended approach to programmatic transaction demarcation.

See also:

+9
source

If your object is configured using Spring, you can turn off the cursor in it ...

0
source

Source: https://habr.com/ru/post/1773601/


All Articles