【发布时间】:2010-12-14 16:15:33
【问题描述】:
调用的方法:
1. Struts 动作
2.服务类方法(@Transactional注解)
3. Xfire webservice调用
包括 struts (DelegatingActionProxy) 和事务在内的一切都是用 Spring 配置的。
持久性是通过 JPA/Hibernate 完成的。
有时网络服务会抛出未经检查的异常。我捕获了这个异常并抛出了一个检查异常。我不希望事务回滚,因为 Web 服务异常更改了当前状态。我已经对方法进行了这样的注释:
@Transactional(noRollbackFor={XFireRuntimeException.class, Exception.class})
public ActionForward callWS(Order order, ....) throws Exception
(...)
OrderResult orderResult = null;
try {
orderResult = webService.order(product, user)
} catch (XFireRuntimeException xfireRuntimeException) {
order.setFailed(true);
throw new WebServiceOrderFailed(order);
} finally {
persist(order);
}
}
我仍然得到这个异常:
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
当我尝试使用 junit 重现此问题时,该事务未标记为回滚,并且仍然可以提交该事务。
如何让 Spring 不回滚事务?
【问题讨论】:
标签: java hibernate spring jpa struts