有一个问题,spring中事务的注解方式
在service层的一个方法配置事务
@Transactional(value = "edwManager", rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public String edwDataSync(String xmlJson){
for (int i = 0; i < 10; i++){
操作数据库插入A表
}
for (int y = 0; y < 10; y++){
操作数据库插入B表
}
}
疑问,事务传播方式如果使用REQUIRES_NEW 这种,那这个方法事务一共起了几个。
A表循环插入了10次,B表也插入了10次
Propagation.REQUIRES_NEW 新建事务,如果当前存在事务,把当前事务挂起。
Your annotation is written on the service, so your service method will be suspended only when other methods that open things execute your service method. Second, what you call in this method should not be a business method, but a dao method. , so you only have one thing.