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:
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:
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.afterTransactionCompletion (raised on commit or rollback)
[Source: Seam in Action (copyright @2009) ; Chapter 9; Page 373]
I looked into the API documentation of the following classes:
Dummy component that lets us install the EjbSynchronizations via the tag transaction:ejb-transaction
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.
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.
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.