简体   繁体   中英

Alternative of @Transactional annotation

What is the alternative of rollback transaction in spring except @Transactional annotation. I have used this annotation but i want the way by which i can rollback transaction in catch block. Is there any way?

Thanx in advance.

Here is a draft:

public class SomeService implements SomeInterface {

   private SomeDao thisDaoWrapsJdbcTemplate;
   private PlatformTransactionManager transactionManager;

   public void setTransactionManager( PlatformTransactionManager transactionManager ) {
      this.transactionManager = transactionManager;
   }

   public void doBusiness( Business: business ) {

      TransactionDefinition def = new DefaultTransactionDefinition();
      TransactionStatus status = transactionManager.getTransaction( def );

      try {

         // do business here
         Money money = Money.LOTS_OF
         ...
         // wire the money in..
         thisDaoWrapsJdbcTemplate.depositLotsOfMoney( money )

         transactionManager.commit( status );

      } catch ( DataAccessException dae ) {

         transactionManager.rollback( status );
         throw dae;
      }
      return;
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM