Spring TransactionTemplate setPropagationBehavior
我想知道 TransactionTemplate
的 setPropagationBehavior
到底是做什么的。谁向谁传播什么?我看到它有详细的文档记录,但我不明白这个 PropagationBehavior
的基本概念。
默认是PROPAGATION_REQUIRED
,那么这是什么意思呢?模板是否报告(传播)失败,反之亦然?
有人可以用基本的方式解释一下这里发生了什么吗?我熟悉数据库术语和事务功能、ACID 等。
非常感谢。
I am wondering what exactly setPropagationBehavior
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TransactionManager 负责处理应用程序中的事务。 PropagationBehavior 是一种告诉经理您希望事务如何表现的方式。 TransactionTemplate 是一个帮助器类,可以为您简化此操作。
REQUIRED 意味着:
1.如果调用方法已经在事务中,它将使用相同的事务
2.如果调用方法在非事务范围中,它将创建新事务
编辑: 我遇到了这篇非常好的文章,讨论 Web 应用程序 spring 和 m 多线程。我认为您应该阅读它。
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.
传播并不是传播失败。
REQUIRED
表示:如果已经有一个事务正在运行,则在当前事务中执行工作(在模板回调中)。如果没有事务正在运行,则启动一个新事务,执行回调中的工作,然后提交事务(如果出现运行时异常,则回滚事务)。在所有情况下,运行时异常总是传播给调用者。它还会导致事务回滚,即使事务不是由该模板启动的。
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.