JBoss.org Community Documentation

Chapter 3. Introduction to EJB3 Stateful Beans

It is very easy to create a Stateful Bean with EJB 3.0. All bean types are homeless in EJB 3.0 so all you have to do to create a Stateful bean is to create a bean class and have it implement at least one interface. Take a look at org.jboss.tutorial.stateful.bean.ShoppingCartBean in the tutorial.

The first thing to notice is that the class is tagged as @Stateful. This marks the class as a stateful bean and the deployer will deploy that class as a stateful bean EJB container.

ShoppingCartBean also implements a remote interface. Take a look at org.jboss.tutorial.stateful.bean.ShoppingCart


Take another look at org.jboss.tutorial.stateful.bean.ShoppingCartBean. Look for the method annotated as @Remove. Instead of explicitly calling EJBObject.remove() in your applications and thus polluting it further with J2EE specific code, any method tagged with @Remove will cause the stateful bean instance to be removed from the container at the end of the method call.