EJB 3.0 - 嵌套事务!= 需要新的? [英] EJB 3.0 - Nested Transaction != Requires New?

查看:20
本文介绍了EJB 3.0 - 嵌套事务!= 需要新的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读了掌握 EJB 3.0"的事务章节 (10),现在我对嵌套事务感到困惑.

I just read the Transactions Chapter (10) of "Mastering EJB 3.0" and now I'm confused about nested transactions.

书上说

"EJB 定义的事务管理器不支持嵌套事务;它只需要支持平面交易."(Site 278,注)

"The EJB-defined transaction manager does not support nested transactions; it requires support for only flat transactions." (Site 278, Note)

这个事实不仅是这本书描述的,我在其他书籍/网站上也发现了这个说法.

This fact is described not only by this book, I found this statement in other books / websites.

但是如果我从 a 中调用一个Requires New"带注释的方法,让我们说Required"带注释的 Methode,我拥有的是一个嵌套事务,不是吗?我可以回滚内部事务或提交它,而不会影响外部事务.如果我想要中止外部事务,我会抛出一个 EJBException 并且整个事务将被回滚.

But if I call a "Requires New" annotated Method from a, let's say "Required" annotated Methode, what I have is a nested transaction, isn't it? I can roll back the inner transaction or commit it, without affecting the outer transaction. And if I want the outer Transaction to be aborted, I throw an EJBException back and the whole transaction will be rolled back.

那么是 EJB 3.0 规范不需要这种行为还是我误解了什么?我只是无法区分嵌套事务和所描述的行为.

So is it just that this behavior is not required by the EJB 3.0 specification or have i misunderstood something? I just can't get the difference between nested transactions and the described behavior.

问候诺曼

推荐答案

RequiresNew 不会创建嵌套事务,因为第一个事务在第二个事务正在运行时挂起.嵌套事务如下所示:

RequiresNew does not create a nested transaction because the first transaction is suspended while the second transaction is running. A nested transaction looks like this:

Nested transaction example
> method1 - begin tran1
  > method2 - begin tran2
    workA
  < method2 - commit tran2
< method1 - rollback tran1 (tran2 also rolled back because it's nested)

相反,RequiresNew 看起来像这样:

Instead, RequiresNew looks like this:

EJB RequiresNew example
> method1 - begin tran1
  > method2 - suspend tran1, begin tran2
    workA
  < method2 - commit tran2, resume tran1
< method1 - rollback tran1 (tran2 remains committed)

这篇关于EJB 3.0 - 嵌套事务!= 需要新的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆