Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Guice事务不';t回滚错误_Java_Spring_Transactions_Guice - Fatal编程技术网

Java Guice事务不';t回滚错误

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

在评估Guice&Spring提供的事务支持时,我了解到Guice仅在异常时提供回滚策略(默认情况下仅在运行时异常时提供)-

在我看来,如果应用程序中出现任何错误——OutOfMemoryError/StackOverflowerError——Spring将回滚事务,但Guice不会

我的理解是正确的还是遗漏了什么?或者我们不需要对错误进行回滚

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);
    }