【发布时间】:2019-06-15 00:34:31
【问题描述】:
我将 @Transactional 与 spring boot 和 jpa 一起使用。但它不起作用。有人可以帮忙吗?
我的插入在 myDAO 中,它在服务类中自动装配。下面的代码是实现服务接口的服务类的方法
class MyService implements Service {
@Transactional(rollbackFor = RuntimeException.class)
public ResponseVO createOrder(params) {
myDAO.insertInTable1(param);
myDAO.insertInTable2(param);//I kept wrong table name in this query such that it throws exception
}
}
【问题讨论】:
-
这里没有错,提供更多信息:)
-
你的回滚只针对
RuntimeException,错误的表不会创建RuntimeException。阅读@Transactional手册。 -
@Zorglube,我尝试使用 new 创建新的运行时异常。即使没有回滚。
-
看来你不明白你在做什么,你不需要自己伪造一个异常,你需要选择你回滚或不回滚什么样的异常。
-
从哪里调用 createOrder 方法?
标签: java spring spring-boot jpa