【发布时间】:2020-01-31 12:51:55
【问题描述】:
我有一个方法会抛出应用程序异常且回滚为真。我想知道是否必须显式调用 ejbContext.setRollbackOnly()?
文档here 说,当异常标记为rollback=true 时,我们不需要调用EjbContext 的setRollbackOnly。
在我的例子中,我捕获了一个 ApplicationException,它的回滚属性设置为 true。然后我显式调用 ejbContext.setRollbackOnly() 因为我在 catch 块中抛出了另一个异常,这个异常将传播到客户端。下面是我的代码sn-p
try {
....
} catch (XYZDirectoryException e) { // ApplicationException marked as rollback=true
ejbContext.setRollbackOnly(); // Is this necessary?
// log exception trace
throw new ServerInternalException("Something bad happened. Please try again or contact administrator. Check logs for more details"); // ApplicationException marked as rollback=false
}
【问题讨论】:
标签: java transactions java-ee-6