Monday, August 9, 2010

@EJB

In EJB3.0 @EJB can be used to inject session beans into any other Session bean or a MDB (Message Driven Bean)

Possible transaction types for EJB3 Session beans are listed below along with the behavior at transaction propagation ...

By default the Transaction Attribute is set to REQUIRED for MDB's even...
so it's better to annotate MDB's onMessage () as NOT_SUPPORTED as a precaution for
transaction timeouts.(if actual transaction is not required..!) most of the times for method calls that wait a longer time..



Transaction Attribute
Caller Transaction Exists
Effect
REQUIRED
No
Container creates a new transaction

Yes
Method joins the callers transaction
REQUIRES_NEW
No
Container creates a new transaction

Yes
Container creates a new transaction and the callers transaction is suspended
SUPPORTS
No
No transaction is used

Yes
Method joins the callers transaction
MANDATORY
No
javax.ejb.EJBTransactionRequiredException is thrown

Yes
Method joins the callers transaction
NOT_SUPPORTED
No
No transaction is used

Yes
The callers transaction is suspended and the method is called without a transaction
NEVER
No
No transaction is used

Yes
javax.ejb.EJBException is thrown