There will be certain use cases in which the application wants to be notified by the EJB container before or after transactions take place, and then use these notifications to manage data and cache. A stateful session bean can receive this kind of notification by the EJB container when it implements the javax.ejb.SessionSynchronization interface. This is an optional feature.
Consider implementing the optional javax.ejb.SessionSynchronization interface if the state data of the stateful session bean needs to be reset after a transaction rollback. The state data of a stateful session bean is not transactional and is not automatically reset to the initial state as the result of a transaction rollback. the interface __ intersace is implemented in the bean class along with other methods javax.ejb.sessionsynchronization in an online shopping site, the client is allowed to select multiple items.. as a developer, how wwould you allow user to cache the items and then write them to the database ofter the transaction is complete - A stateless session bean must not implement the javax.ejb.SessionSynchronization interface. Message-driven Bean - Client view: the existence of a MDB is completely hidden behind the destination or endpoint for which the MDB is the message listener - Step 2 (Dependency injection) includes injecting SessionContext.----- The addition of these transaction callback methods by the SessionSynchronization interface expands the bean's awareness of its life cycle to include a new state, the Transactional Method-Ready state. Like Show 0 Likes (0) - (Stateful SB) May implement the javax.ejb.SessionSynchronization interface. - (Stateless SB) May implement the javax.ejb.TimedObject interface. - May implement the session bean’s business, component or web service endpoint interface - May implement the ejbCreate method(s).
EJB Specifications say that : "Only a stateful Session bean with container-managed transaction demarcation may implement the SessionSynchronization interface. A stateless Session bean must not implement the SessionSynchronization interface. My doubt is why only stateful session beans can optionally implement SessionSynchronization interface ?
10.Which of the following statements are true concerning objects that implement the javax.ejb.SessionSynchronization interface? The container automatically calls the afterBegin() method when a stateful session bean enters a transaction The beforeCompletion() call occurs before the transaction is prepared to commit
All Implemented Interfaces: Serializable, Comparable public enum SessionSynchronization extends Enum
Using Container-Managed Transactions. Using the SessionSynchronization Interface. Using the Java Transaction API (JTA) for Bean-Managed Transactions. Troubleshooting.10.