我有以下代码:
@Service
public class MyService implements IMyService {
@Inject
IAnotherService anotherService;
// injects go here
// some code
@Transactional(isolation=Isolation.SERIALIZABLE)
public Result myMethod() {
// stuff done here
return this.myPrivateMethod()
}
private Result myPrivateMethod() {
// stuff done here
// multiple DAO SAVE of anObject
anotherService.processSomething(anObject);
return result;
}
}
@Service
public class AnotherService implements IAnotherService {
// injections here
// other stuff
@Transactional(isolation=SERIALIZABLE)
public Result processSomething(Object anObject) {
// some code here
// multiple dao save
// manipulation of anObject
dao.save(anObject);
}
}
@Transactional
行为是否会传播到myPrivateMethod,即使它是私有的?Runtime Exception
上发生processSomething()
,processSomething
调用myPrivateMethod
,myPrivateMethod
和myMethod
会回滚吗? @Service
的情况下实现这一目标?如何在@Transactional
上下文中的公共服务方法中提取方法并调用多个私有方法?isolation=Isolation.SERIALIZABLE
选项是synchronized
方法的一个很好的替代方案吗?我知道这已经回答了,但我仍然怀疑。
答案 0 :(得分:3)