Guest User

Untitled

a guest
Oct 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. @Autowired
  2. private PlatformTransactionManager transactionManager;
  3.  
  4. public void doSomething() {
  5.  
  6. DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
  7. definition.set...
  8. // begin transaction
  9. TransactionStatus transaction = transactionManager.getTransaction(definition);
  10.  
  11. try {
  12. // do something
  13. transactionManager.commit(transaction);
  14. } catch (Exception e) {
  15. // here transaction should be still active
  16. transactionManager.rollback(transaction);
  17. // here transaction should be rolled back
  18. throw e;
  19. }
  20. }
Add Comment
Please, Sign In to add comment