Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 3/2/2005; 8:28:12 AM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Friday, February 25, 2005

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    comment []

© Copyright 2005 Debu Panda.

PS: These are my own thoughts and not of my employer ..



Click here to visit the Radio UserLand website.
 


February 2005
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28          
Jan   Mar