Khaled said: I do not understand why in Message Driven Bean I cannot user other transaction attributes such as RequiresNew or Mandatory
Mandatory means a transaction is required when the method is invoked. MDB's have no clients and container invokes the onMessage method, so there is no incoming transaction and hence Mandatory is not permitted.
Requires new means there is an incoming transaction, it is suspended and new transaction is started. Since there is no client there is no incoming client. So RequiredNew makes no sense.
I find this explanations from O'Reilly's book very clear:
Message-driven beans may declare only the NotSupported or Required transaction attribute. The other transaction attributes don't make sense in message-driven beans because they apply to client-initiated transactions. The Supports, RequiresNew, Mandatory, and Never attributes are all relative to the transaction context of the client. For example, the Mandatory attribute requires the client to have a transaction in progress before calling the enterprise bean. This is meaningless for a message-driven bean, which is decoupled from the client.
The NotSupported transaction attribute indicates that the message will be processed without a transaction. The Required transaction attribute indicates that the message will be processed with a container-initiated transaction.
Camilo Morales<br />SCJP 5, SCBCD 5
Joined: Jul 15, 2006
When I read this explanation for the first time, I thought that "Client" only means an application client and it did not come to my mind that it could be an EJB well. That's why there was a confusion about this explanation.
When reading Amol explanation i thought that it could be another session that could invoke this statement. Exactly this statement made me figure this out
container invokes the onMessage method,
Thank you both for help. [ August 23, 2007: Message edited by: Khaled Mahmoud ]