java事务调用事务_java – 了解Spring事务 – 事务方法调用另一个事务方法时会发生什么?...
发布日期:2021-06-24 14:59:08 浏览次数:2 分类:技术文章

本文共 1101 字,大约阅读时间需要 3 分钟。

只要了解Spring事务的工作,我想知道在以下情况下会发生什么,一个标记为@Transactional的方法调用另一个标记为@Transactional的方法。

假设配置使用所有默认设置。

@Service("myService")

@Transactional

public MyService{

public void myServiceMethod(){

myDAO.getSomeDBObjects();

}

}

@Repository("myDAO")

@Transactional

public MyDAOWithUsesBeyondMyService{

public void getSomeDBObjects(){...}

}

现在如果我要输入MyService.myServiceMethod(),它将显然启动一个事务。那么在钻入myDAO.getSomeDBObjects()会发生什么?事实已经存在的事实不会导致新的交易出生,还是我在这里创建两个交易?

传播中的文档(引用如下)似乎涵盖了这一点,但是我想验证我的理解,对于我的处女大脑来了解一下,这是一个很大的一部分。

Propagation: Typically, all code

executed within a transaction scope

will run in that transaction. However,

you have the option of specifying the

behavior in the event that a

transactional method is executed when

a transaction context already exists.

For example, code can continue running

in the existing transaction (the

common case); or the existing

transaction can be suspended and a new

transaction created. Spring offers all

of the transaction propagation options

familiar from EJB CMT. To read about

the semantics of transaction

propagation in Spring, see Section

10.5.7, “Transaction propagation”.

转载地址:https://blog.csdn.net/weixin_33510225/article/details/114827889 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:简述java中对象的关系_Java中类的创建及类与对象的关系
下一篇:富文本编辑器内容传到java后天_关于layui富文本编辑器同步编辑器内容到textarea layedit.sync(index)...

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月27日 07时13分17秒