问题描述
在评估Guice&Spring提供的Transaction支持时,我知道guice仅在Exception(默认情况下仅在RuntimeExceptions)上提供回滚策略-
private boolean rollbackIfNecessary(
Transactional transactional,Exception e,EntityTransaction txn) {
boolean commit = true;
//check rollback clauses
for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) {
//if one matched,try to perform a rollback
if (rollBackOn.isInstance(e)) {
commit = false;
//check ignore clauses (supercedes rollback clause)
for (Class<? extends Exception> exceptOn : transactional.ignore()) {
//An exception to the rollback clause was found,DON'T rollback
// (i.e. commit and throw anyway)
if (exceptOn.isInstance(e)) {
commit = true;
break;
}
}
//rollback only if nothing matched the ignore check
if (!commit) {
txn.rollback();
}
//otherwise continue to commit
break;
}
}
return commit;
}
}
尽管spring提供了即使发生错误也可以回滚的功能-
@Override
public boolean rollbackOn(Throwable ex) {
return (ex instanceof RuntimeException || ex instanceof Error);
}
在我看来,如果应用程序出现任何错误-OutOfMemoryError / StackOverflowError-Spring将回滚事务,但是Guice不会。
我对这种理解是正确的还是缺少什么?还是我们不需要回退错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)