@zero1036
2019-03-08T07:17:15.000000Z
字数 1643
阅读 1708
Java-Spring
// readOnly=true只读,不能更新,删除@Transactional (propagation = Propagation.REQUIRED,readOnly=true)// 设置超时时间@Transactional (propagation = Propagation.REQUIRED,timeout=30)// 设置数据库隔离级别@Transactional (propagation = Propagation.REQUIRED,isolation=Isolation.DEFAULT)
默认遇到throw new RuntimeException("...");会回滚
捕获的throw new Exception("...");不会回滚
需要捕获Exception回滚方法:rollbackFor = Exception.class
手动回滚方法:TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class, isolation = Isolation.REPEATABLE_READ)public void testInsert(int index) throws Exception {OrderDO orderDO = new OrderDO();orderDO.setThirdOrderId("1000");int rowCount = this.orderMapper.insertOrder(orderDO);if (index == 1) {throw new RuntimeException("wrong");}if (index == 2) {throw new Exception("wrong");}if (index == 3) {TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();}}