什么时候应该将REQUIRED和NOT_SUPPORTED用作MDB的@TransactionAttribute值? [英] When should I use `REQUIRED` vs `NOT_SUPPORTED` as a the value of @TransactionAttribute for an MDB?

查看:189
本文介绍了什么时候应该将REQUIRED和NOT_SUPPORTED用作MDB的@TransactionAttribute值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解容器管理的交易(CMT).我还知道所列举的不同的可能值键入TransactionAttributeType.由于客户端从不直接调用MDB,因此REQUIREDNOT_SUPPORTED以外的属性类型对MDB没有意义,因为没有客户端发起的事务要加入.因此,什么时候应该用REQUIRED vs NOT_SUPPORTED注释MDB的onMessage()方法?没有提到这两个选项的默认行为是什么?

I know about container managed transactions(CMT). I also know about the different possible values of the enumerated type TransactionAttributeType. Since the client never calls a MDB directly, the attribute types other than the REQUIRED and NOT_SUPPORTED do not make sense for MDB's as there is no client initiated transaction to join to. So when should I annotate the onMessage() method of an MDB with REQUIRED vs NOT_SUPPORTED? What will be the default behavior in none of the two options is mentioned?

推荐答案

这两个选项都不是的默认行为是 提到过?

What will be the default behavior in none of the two options is mentioned?

Container管理的MDB的默认行为是NOT_SUPPORTED.

The default behavior for Container-managed MDBs is NOT_SUPPORTED.

所以我什么时候应该用以下方式注释MDB的onMessage()方法 需要vs不支持吗?

So when should I annotate the onMessage() method of an MDB with REQUIRED vs NOT_SUPPORTED?

使用NOT_SUPPORTED意味着-如果onMessage()中发生故障-发生故障之前发生的任何更新/操作都不会回滚;对于涉及不同资源的原子操作来说,这是不希望的.

Using NOT_SUPPORTED means - if a failure occurs in onMessage() - any updates/operations that occurred prior to the failure will not be rolled back; this is undesirable for atomic operations involving disparate resources.

如果您不希望这种行为,请使用REQUIRED,在onMessage()中放入try/catch,并在发生任何异常时在catch()中调用setRollbackOnly().如果onMessage()在不同资源上执行多项操作,则需要XA驱动程序;否则,您将需要XA驱动程序.例如,在同一事务中更新数据库并发送新的JMS消息肯定会需要XA兼容驱动程序.

If you don't want that behavior, use REQUIRED, put a try/catch in onMessage(), and call setRollbackOnly() in catch() when any exceptions occur. You will need XA drivers if onMessage() is performing multiple operations across different resources; for instance, updating a database and sending a new JMS message in the same transaction will most certainly require XA compatible drivers.

仅MDB支持或不支持

MDB可以使用REQUIREDNOT_SUPPORTED事务属性;其他属性没有意义,因为它们需要客户端上下文.

MDB's may use REQUIRED or NOT_SUPPORTED transaction attributes; other attributes don't make sense since they require client context.

容器始终在调用onMessage()之前开始新事务.如果从onMessage()调用另一种方法,则容器将沿当前事务上下文传递.

The container always starts a new transaction before calling onMessage(). If another method is called from onMessage(), the container passes along the current transaction context.

这篇关于什么时候应该将REQUIRED和NOT_SUPPORTED用作MDB的@TransactionAttribute值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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