我有以下代码:
@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
中呢?- 如果在
processSomething()
上发生RuntimeException
,并且从myPrivateMethod
调用了processSomething
,那么myPrivateMethod
和myMethod
是否会回滚? - 如果问题1和2的答案为否,那么我如何实现而不必创建另一个
@Service
呢?如何在@Transactional
上下文中提取方法并调用多个私有方法? isolation=Isolation.SERIALIZABLE
选项是synchronized
方法的一个好替代吗?
我知道这个问题已经被解答了,但我仍然有疑问。