2. Stateful Beans - JohnyzHub/EJB3x GitHub Wiki
Stateful Session Beans
@Stateful(passivationCapable=false) – Deactivates passivation behaviour. It is true by default.
@PrePassivate – Invokes the method before stateful session bean is passivated.
@PostAcitvate – Invokes the method after the stateful session bean made active from passivation.
@StatefulTimeout – Duration a stateful session is permitted to be remain idle.
The value and unit description is same as explained for @AccessTimeout.
@Remove – notifies ejb container to remove stateful bean instance permanently from memory.
The method with this annotation is called before @predestroy if any.
- Implement SessionSynchronization interface
or - Annotate methods using
- a. @AfterBegin -- notifies bean that a new transaction has begun.
- b. @BeforeCompletion -- Indicates that the transaction is going to be committed
- c. @AfterCompletion -- Indicates that the transaction has been completed
or
- Declare methods in deployment descriptor
This facilitates the stateful session bean with transaction synchronization notifications.
The sesssionsynchronization applies only for stateful session bean with container managed transaction(CMT) demarcation.
If a stateful session bean's lifecycle callback method @PostConstruct, @PreDestroy, @PrePassivate or @PostAcitvate is invoked, the sesssionsynchronization callbacks for the transaction are not called on the bean instance.
To understand the sequence of callback methods for a stateful session bean,
Please refer diagram in page#83 of the EJB spec Stateful session bean lifecycle diagram