默认遇到throw new RuntimeException(“…”);会回滚
需要捕获的throw new Exception(“…”);不会回滚
指定回滚
@Transactional(rollbackFor=Exception.class) public void methodName() { // 不会回滚 throw new Exception("..."); }
指定不回滚
@Transactional(noRollbackFor=Exception.class) public ItimDaoImpl getItemDaoImpl() { // 会回滚 throw new RuntimeException("注释"); }
如果有事务,那么加入事务,没有的话新建一个(不写的情况下)
@Transactional(propagation=Propagation.REQUIRED)
容器不为这个方法开启事务
@Transactional(propagation=Propagation.NOT_SUPPORTED)
readOnly=true只读,不能更新,删除
@Transactional (propagation = Propagation.REQUIRED,readOnly=true)
设置超时时间
@Transactional (propagation = Propagation.REQUIRED,timeout=30)
设置数据库隔离级别
@Transactional (propagation = Propagation.REQUIRED,isolation=Isolation.DEFAULT)