开发者

Spring TransactionTemplate setPropagationBehavior

I am wondering what exactly set开发者_高级运维PropagationBehavior of the TransactionTemplate does. Who propagats what to whom? I see it is well documented but I don't grasp the basic concept of this PropagationBehavior.

The default is PROPAGATION_REQUIRED, so what does this meen? Does the template report (propagate) failures or vice versa?

Can someone please explain in a basic way what is going on here, I am familiar with database terminology and transaction functionality, ACID and so on.

Thanks so much.


TransactionManager takes care of transactions in application. PropagationBehavior is a way how to tell your manager how do you want transactions to behave. TransactionTemplate is a helper class to simplifi this for you.

REQUIRED means:

1.If the calling method is already in a transaction it will use the same transaction

2.If the calling method is in a non-transaction scope it will create new transaction

EDIT: I came accross this very good article dealing with web applications spring andm multithreading. I think you should read it.


The propagation is not about propagating failures. REQUIRED means: if there is already a transaction running, do the work (in the template callback) in the current transaction. If there is no transaction running, start a new one, execute the work in the callback, and then commit the transaction (or rollback it if there is a runtime exception).

In all the cases, a runtime exception is always propagated to the caller. It also cause the transaction to rollback, even if it wasn't started by this template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜