java - 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
......任何帮助,因为我尝试了很多但从未达到?
解决方案
RollbackException 是一个 RuntimeException,因此不是从 Exception 派生的。但我怀疑 RuntimeException 的 norollback 也无济于事,因为原因可能是其他原因。可能是超时,乐观锁定问题,重复唯一 ID,......可能有很多原因导致发生与抛出的异常无关的回滚。
推荐阅读
- android - Android 深度链接 Intent 问题
- jdbc - 为什么我不能为 oracle 12c 创建 jndi 数据源?
- java - 如何通过 JPQL 从 SQL 计数返回布尔结果
- html - 在非全宽元素中设置全宽动态元素样式的最佳方法是什么?
- dart - Flutter:无法使用任何包获取位置 - 尝试了各种包 - getLocation 块
- php - 如何在 PHP 中使用存储在数据库中 SQL 查询中的变量
- deep-learning - RNN 如何从图像中提取特征
- android - React Native:悬停图像 onPress
- javascript - getorgchart - 我想动态分配颜色
- function - 接受一个参数的函数的值,该参数本身就是一个函数