About using <transaction:ejb-transaction/> in components.xml
mchisty Dec 15, 2012 1:21 AMHello,
I have a confusion regarding the <transaction:ejb-transaction/> tag in compoenents.xml. Why and when is it necessary?
So far after doing some goole search, I have understood the followings:
Point 1
According to Dan Allen (Author of Seam in Action),
<<
If your components rely on container-managed transactions, available in an EJB environment, Seam works alongside the UserTransaction on the EJBContext to capture transaction synchronization events. Since Seam isn’t in control of container-managed transactions, it’s necessary to register Seam to be notified of the transaction boundaries:
<tx:ejb-transaction/>
This configuration activates a stateful session bean that implements the Session-Synchronization interface to capture transaction events from the EJB container. This SFSB is packaged in jboss-seam.jar, which must be bundled in the EAR. From this SFSB, Seam passes on the following two events to other Seam components using its own internal event mechanism, the same events Seam raises for Seam-managed transactions:
- org.jboss.seam.beforeTransactionCompletion
- org.jboss.seam.afterTransactionCompletion (raised on commit or rollback)
>>
[Source: Seam in Action (copyright @2009) ; Chapter 9; Page 373]
Point 2
I looked into the API documentation of the following classes:
- org.jboss.seam.transaction.EjbTransaction
- org.jboss.seam.transaction.EjbSynchronizations
- javax.ejb.SessionSynchronization
About org.jboss.seam.transaction.EjbTransaction:
<<
Dummy component that lets us install the EjbSynchronizations via the tag transaction:ejb-transaction
>>
[Ref: http://docs.jboss.org/seam/2.0.0.GA/api/]
About org.jboss.seam.transaction.EjbSynchronizations:
<<
Receives JTA transaction completion notifications from the EJB container, and passes them on to the registered Synchronizations. This implementation is fully aware of container managed transactions and is able to register Synchronizations for the container transaction.
>>
[Ref: http://docs.jboss.org/seam/2.0.0.GA/api/org/jboss/seam/transaction/EjbSynchronizations.html]
About javax.ejb.SessionSynchronization (the super interface of org.jboss.seam.transaction.EjbSynchronizations):
<<
The SessionSynchronization interface allows a stateful session bean instance to be notified by its container of transaction boundaries.
Only a stateful session bean with container-managed transaction demarcation can receive session synchronization notifications. Other bean types must not implement the SessionSynchronization interface or use the session synchronization annotations.
A stateful session bean class is not required to implement this interface.
>>
[Ref: http://docs.oracle.com/javaee/5/api/javax/ejb/SessionSynchronization.html]
From the above statements/docs as mentioned, is it okay to conclude that,
- if we only use POJO (Seam compoents with @Name annotation) and/or stateless EJBs (beans with bean with @Stateless annotation) and,
- if we DO NOT use any SFSB (i.e. no bean with @Stateful annotation),
then we do not need to use <transaction:ejb-transaction/> tag in the components.xml?
Any feedback would be appreciable.
With Thanks,
... Chisty