【发布时间】:2015-12-19 11:26:37
【问题描述】:
我有以下代码:
@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()上,并且从myPrivateMethod调用processSomething,那么myPrivateMethod和myMethod会回滚吗? - 如果对 1 和 2 的回答是否定的,我怎样才能在不创建另一个
@Service的情况下做到这一点?如何在@Transactional上下文中的公共服务方法中提取方法并调用多个私有方法?。 -
isolation=Isolation.SERIALIZABLE选项是synchronized方法的良好替代品吗?。
我知道这个问题已经得到解答,但我仍然有疑问。
【问题讨论】:
-
到目前为止你找到的答案告诉你什么? 1. 是 2. 是 3. 不适用,因为 1 && 2 4. 不,因为它只有在事务容器中调用该方法时才有效。
-
stackoverflow.com/questions/4396284/… ---> 找到了一些可以部分回答我的问题的参考资料,但主要主题并不集中在与我相同的案例上。我真的必须确定事务注释是否真的适用于我的情况。对于问题 4:如果我强制 Propagation.MANDATORY?
标签: java spring transactions isolation