首页 > 解决方案 > RollbackException:事务标记为 rollbackOnly 尽管将其设置为 norollbackfor

问题描述

伙计们我有这个方法

@Component
public class Services implements Serializable {

  @Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = Exception.class, timeout = -1)
  public void method() {

   try {
      addBean(bean1);
    } catch (Exception e) {
      e.printStackTrace();
    }

    addBeans(List<Beans); // Adds Lists of beans
    editBean(bean1); // Edit first bean "bean1"
  }
}

但我总是得到org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly......任何帮助,因为我尝试了很多但从未达到?

标签: javaspringhibernatetransactions

解决方案


RollbackException 是一个 RuntimeException,因此不是从 Exception 派生的。但我怀疑 RuntimeException 的 norollback 也无济于事,因为原因可能是其他原因。可能是超时,乐观锁定问题,重复唯一 ID,......可能有很多原因导致发生与抛出的异常无关的回滚。


推荐阅读