【发布时间】:2020-03-28 17:40:35
【问题描述】:
我有一个例子,它需要通过条件外循环回滚一些方法内循环。 我使用 EntittyManager 和 @Transactional。 因为循环中的逻辑很复杂,所以我不想进入 2 循环。 如何实现回滚、提交?
@Service
@Transactional
public class StudentServiceImpl implement StudentService {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean execute(List<ADto> adtoList) {
boolean a = true;
for(ADto dto : adtoList) {
boolean a = method1(dto); // call to sub method2, method3 to insert data into A, B table
if(a == false) {
break;
}
method4(); // do insert data into D, E table
method5(); // do update into F table
}
if(a == false) {
// need rollback all inserted data in A, B table which is inserted in method1, method2, method3 (of all loop element)
// still commit all inserted data at method4(), method5() (of all loop element)
}
【问题讨论】:
标签: spring-boot jpa transactions entitymanager