Java Guice事务不';t回滚错误
在评估Guice&Spring提供的事务支持时,我了解到Guice仅在异常时提供回滚策略(默认情况下仅在运行时异常时提供)- 在我看来,如果应用程序中出现任何错误——OutOfMemoryError/StackOverflowerError——Spring将回滚事务,但Guice不会 我的理解是正确的还是遗漏了什么?或者我们不需要对错误进行回滚Java Guice事务不';t回滚错误,java,spring,transactions,guice,Java,Spring,Transactions,Guice,在评估Guice&Spring提供的事务支持时,我了解到Guice仅在异常时提供回滚策略(默认情况下仅在运行时异常时提供)- 在我看来,如果应用程序中出现任何错误——OutOfMemoryError/StackOverflowerError——Spring将回滚事务,但Guice不会 我的理解是正确的还是遗漏了什么?或者我们不需要对错误进行回滚 private boolean rollbackIfNecessary( Transactional transactional, Ex
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;
}
}
@Override
public boolean rollbackOn(Throwable ex) {
return (ex instanceof RuntimeException || ex instanceof Error);
}