1.spring运行期例外(unchecked Exception)事务可以回滚,用户例外(checked Exception,即try...catch...finally块)事务不回滚;
2.若要checked Exception回滚,在需要回滚的方法前添加注解:
@Transactional(rollbackFor=Exception.class)
3.要unchecked Exception不回滚,在需要回滚的方法前添加注解:
@Transactional(norollbackFor=RuntimeException.class)
4.添加@Transactional(propagation=Propagation.NOT_SUPPORTED)注解于方法前,取消该方法的事务,如查询数据不需要事务;