ps:mysql中查看正在运行的事务的语句是:
1
| SELECT * FROM information_schema.innodb_trx;
|
查询所有事务的语句(这个会将所有信息放到Status字段里):
1
| SHOW ENGINE INNODB STATUS;
|
方法一:
使用PlatformTransactionManager
加TransactionDefinition
具体的使用方法如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| @Autowired private PlatformTransactionManager platformTransactionManager;
@Autowired private TransactionDefinition transactionDefinition;
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition); try{ platformTransactionManager.commit(transactionStatus); }catch (Exception e) { platformTransactionManager.rollback(transactionStatus); }
|
方法二:
使用TransactionAspectSupport
和@Transactional
注解
使用方法如下:
1 2 3 4 5 6 7 8 9 10 11
| @Transactional(rollbackFor = Exception.class) public void method(){ Object savepoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); try{ }catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savepoint); } }
|