【发布时间】:2020-05-08 05:09:00
【问题描述】:
我有一些类似下面的代码。
public class ServiceImpl implements Service
{
@Transactional
public myObject methodOne()
{
if (myCondition)
return methodTwo();
else
anotherMethod();
}
public myObject methodTwo()
{
int retryCount = 1;
myObject myObject = null;
while (retryCount <= 10) {
try {
myObject = repository.save();
break;
} catch (DataIntegrityViolationException ignored) {
retryCount++;
}
}
if (myObject == null){
throw new MyException();
}
}
}
但它会抛出异常
事务静默回滚,因为它已被标记为 仅回滚
即使我在methodTwo() 和myObject != null 中也遇到了。谁能帮帮我!!!
【问题讨论】:
标签: java spring transactions spring-data-jpa