View RSS Feed


Stateful Session Bean

Rate this Entry
, 01-02-2012 at 06:52 PM (1014 Views)
A stateful session bean is an enterprise bean (EJB component) that serves to be a client’s server side extension. It is created by one client and hence it works for just that client till the drop takes place in client connection or removal of the bean takes place explicitly. The stateful Bean (EJB Component) implements the interface javax.ejb.SessionBean and deploys to the “stateful” which is the declarative attribute. They are called stateful as conversational state is being maintained by them with client.

Java Code: This is the example code for stateful session bean
import java.util.Collection;
import javax.ejb.Remote;
public interface Cart {
    public void addItem(String item);
    public void removeItem(String item);
    public Collection getItems();

import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
public class CartBean implements Cart {
    private ArrayList items;
    public void initialize() {
        items = new ArrayList();
    public void addItem(String item) {
    public void removeItem(String item) {
    public Collection getItems() {
        return items;

Submit "Stateful Session Bean" to Facebook Submit "Stateful Session Bean" to Digg Submit "Stateful Session Bean" to Submit "Stateful Session Bean" to StumbleUpon Submit "Stateful Session Bean" to Google

Updated 01-14-2012 at 07:12 PM by EJB

Session Bean