![](/img/trans.png)
[英]Overriding transaction propagation levels for methods having Spring's @transactional
[英]@Transactional propagation on private methods
我有以下代碼:
@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()
上發生Runtime Exception
,並且從myPrivateMethod
調用processSomething
, myPrivateMethod
和myMethod
會回滾嗎? @Service
情況下實現這一目標? 如何在@Transactional
上下文中的公共服務方法中提取方法並調用多個私有方法? isolation=Isolation.SERIALIZABLE
選項是synchronized
方法的一個很好的替代方案嗎? 我知道這已經回答了,但我仍然有疑慮。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.