Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transactions questions

 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read in the book : EJB 3.0 that "Message Driven Beans" can only have two transaction attributes which are :

1- Not Supported
2- Required

I do not understand why in Message Driven Bean I cannot user other transaction attributes such as RequiresNew or Mandatory.

Thanks in advance.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Camilo Morales
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Regards,
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic