Stateful Session Bean also gets simpler with EJB 3.0. Everyone used a Cart example for stateful session bean for EJB 1.x and EJB 2.x days so let me reuse the same example for simplicity and to demonstrate how simple it is with EJB 3.0
SFSB supports callback for lifecycle events such as activation(PostActivate) /passivation (PreActivate) and creation (PostConstruct) and destruction(PreDestroy). You can define the lifecycle event either in the bean class or in an external listener class. In our example we will use a PostConstruct method in the bean class. PostConstruct are similar to ejbCreate for EJB 2.x EJBs.
The remote interface for the CartEJB is a pure Java interface and it does not extend EJBObject.
import javax.ejb.Remote;
@Remote
public interface Cart {
public void addItem(String item);
..... }
The EJB is a plain Java class that implements its business interface.
@Stateful public class CartBean implements Cart { private ArrayList items;
@PostConstruct public void initialize() { items = new ArrayList(); } public void addItem(String item) { items.add(item); } ...
.. }
You will not need any EJBHome interface and deployment descriptors!
7:00:44 AM
|