在事务中打开新事务时提交

发布于 2024-11-15 08:35:09 字数 1250 浏览 2 评论 0原文

我使用 Ejb3.0、Weblogic 11g、JDBC 调用

在另一个部署 EAR 中远程运行的方法。

远程部署中的方法被调用,但它带有注释 @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

问题是,在调用远程方法之前我在数据库中执行的所有逻辑都不会提交,直到远程方法完成为止。

我愿意做的是提交让“之前”的逻辑发生”,并且当我在远程调用之后返回以正常继续时。

有什么想法吗?

需要解释一些代码:

@CallByReference
@Stateless(mappedName = "ejb/OperatorProccessBean")
@Local({ OperatorProccessBeanLocal.class })
@Remote({ OperatorProccessBeanRemote.class })
public class OperatorProccessBean implements OperatorProccessBeanLocal,  
 OperatorProccessBeanRemote
{   

...

   SBNDispatchBeanRemote SBNDispatchBean = (SBNDispatchBeanRemote) context.lookup("ejb/SBNDispatchBean#com.mirs.sbn.dispatch.SBNDispatchBeanRemote");
    if (SBNDispatchBean == null)
    {
            logger.error(TAG + " SBNDispatchBean is null");

    }
    else
    {
         //until here I want all my data to be commited without waiting for the upcoming remote method to finish
         SBNDispatchBean.updateSubscriberInBlockingList(...);
    }
...
 }

现在是方法 updateSubscriberInBlockingList() 注释有

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

我希望在调用该方法之前提交数据,

提前致谢 。 射线。

Using Ejb3.0, Weblogic 11g, JDBC

I am invoking a method which is running remotely in another deployment EAR.

The method in the remote deployment being invoked but it's annotated with the
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

the problem is that all the logic I do in the database before the remote method is being invoked wont commit till the remote method finished.

What I willing to do is a commit to let the "before" logic take place" and when I get back after the remote call to continue normally.

Any idea?

Some code to explain:

@CallByReference
@Stateless(mappedName = "ejb/OperatorProccessBean")
@Local({ OperatorProccessBeanLocal.class })
@Remote({ OperatorProccessBeanRemote.class })
public class OperatorProccessBean implements OperatorProccessBeanLocal,  
 OperatorProccessBeanRemote
{   

...

   SBNDispatchBeanRemote SBNDispatchBean = (SBNDispatchBeanRemote) context.lookup("ejb/SBNDispatchBean#com.mirs.sbn.dispatch.SBNDispatchBeanRemote");
    if (SBNDispatchBean == null)
    {
            logger.error(TAG + " SBNDispatchBean is null");

    }
    else
    {
         //until here I want all my data to be commited without waiting for the upcoming remote method to finish
         SBNDispatchBean.updateSubscriberInBlockingList(...);
    }
...
 }

Now the method updateSubscriberInBlockingList() is annotated with

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

i want the data to be commited before that method being invoked.

Thanks in advance,
ray.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘东忘西忘不掉你 2024-11-22 08:35:09

现在 updateSubscriberInBlockingList() 方法使用 @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) 进行注释

我希望在调用该方法之前提交数据。

鉴于您正在使用容器管理的事务,这是不可能的。其背后的基本原理是,当容器已经在执行事务时,启动新事务将导致原始事务被挂起。当新事务提交后,原始事务将恢复。

此行为不可配置,因为 EJB 容器和 JTA 事务管理器应遵循 JTA 规范中指定的行为,该规范源自 X/Open DTP 事务模型。在X/Open DTP模型中,如果有一个新的事务正在启动,而另一个事务正在进行中,则当前的事务将被暂停,并在稍后的时间点恢复。应该注意的是,没有任何事务模型可能(我没有研究全部)允许提交当前事务并启动新事务。我只看到各种事务处理模型支持嵌套事务或挂起事务。

如果要提交工作,则必须完全终止现有事务上下文,以便现有事务提交,然后启动新事务。

Now the method updateSubscriberInBlockingList() is annotated with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

I want the data to be commited before that method being invoked.

Given that you are using container managed transactions, it is not possible. The rationale behind this, is that when the container is already performing a transaction, then starting a new transaction will result in the original being suspended. When the new transaction has committed, the original transaction will be resumed.

This behavior is not configurable, for the EJB container and the JTA Transaction Manager is expected adhere to the behavior specified in the JTA specification, which is derived from X/Open DTP transaction model. In the X/Open DTP model, if there is a new transaction is started, while another is in progress, the current one is suspended, and resumed at a later point in time. It should be noted that no transaction model, would possibly (I haven't studied all) allow for committing the current transaction and starting a new one. I have only seen nested transactions or suspended transactions being supported in the various transaction processing models.

If you want to have the work committed, you must have the existing transaction context terminated completely, so that the existing transaction will commit, and then start the new transaction.

青瓷清茶倾城歌 2024-11-22 08:35:09

将“远程调用之前”逻辑放在一个单独的 bean 方法中,并用 REQUIRES_NEW 进行注释。因此,您将拥有三个事务:

  • 一个用于 main 方法(但在远程调用完成之前不会执行任何操作);一个用于主方法(但在远程调用完成之前不会执行任何操作);
  • 一个是远程调用之前的逻辑;
  • 一个用于远程调用。

Put the "before remote call" logic in a separate bean method annotated with REQUIRES_NEW as well. You will thus have three transactions :

  • one for the main method (but which won't do anything until th remote call is done);
  • one for the logic before the remote call;
  • one for the remote call.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文