When should I use `REQUIRED` vs `NOT_SUPPORTED` as a the value of @TransactionAttribute for an MDB?

故事扮演 提交于 2020-01-04 08:03:14

问题


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?


回答1:


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

The default behavior for Container-managed MDBs is NOT_SUPPORTED.

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

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.

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's support only REQUIRED or NOT_SUPPORTED

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

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.




回答2:


I'm interested at this discussion. I was convinced that specs indicates that default transaction attribute is REQUIRED.

Some guys in another stackoverflow discussion :

What is the default TRANSACTION ATTRIBUTE for MDBS?

spoke about exception on Weblogic server implementation.



来源:https://stackoverflow.com/questions/24120389/when-should-i-use-required-vs-not-supported-as-a-the-value-of-transactionat

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