Question about spring transaction propagation

橙三吉。 提交于 2019-12-20 10:42:25

问题


I have a question about spring transaction propagation. If I use @Transactional(propagation = Propagation.REQUIRED) to annotate a method m1. When execution logic enter m1, if there is already a transaction, m1 will use that one. When after m1, what about the transaction? It ends or still open?(if I call m1 in another method, and after the invocation there is still other things to do).

In summary, I want to know when exiting an annotated method, the transaction ends or still open?

Great thanks.


回答1:


Propagation.REQUIRED (documented here) will create a new transaction (if none exists for the current thread), or will join an existing transaction (if one exists).

When the method exits, then the transaction will be completed (if entering the method caused a transaction to be created), or will leave the transaction open (if a transaction already existed when the method was entered). In other, words, it's symmetrical, and will leave the thread's transactional state in the same state it was before the method was entered.



来源:https://stackoverflow.com/questions/2754160/question-about-spring-transaction-propagation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!