Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Implementing an EJB 3.0 Stateless Session Bean

EJB 3.0 greatly simplifies the development of stateless session beans, removing many complex development tasks. For example:

- The bean class can be a plain old Java object (POJO); it does not need to implement `javax.ejb.SessionBean`.

- Home (`javax.ejb.EJBHome` and `javax.ejb.EJBLocalHome` ) and component (`javax.ejb.EJBObject` and `javax.ejb.EJBLocalObject`) business interfaces are not required.

  If you choose to use a remote component interface, you can use a plain old Java interface (POJI); it does not need to extend `javax.ejb.EJBObject`.

- Annotations are used for many features.

- A `SessionContext` is not required: you can simply use `this` to resolve a session bean to itself.

For more information, see "What is a Stateless Session Bean?".

Note: You can download an EJB 3.0 stateless session bean code example from: `http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30slsb/doc/how-to-ejb30-stateless-ejb.html`.

To implement an EJB 3.0 stateless session bean:

1. Optionally, create one or more remote component interfaces and/or local interfaces for your stateless session bean.

   You can create a plain old Java interface (POJI) and define it as a remote interface with the `@Remote` annotation or as a local interface using the `@Local` annotation.

   You can specify multiple interfaces using the annotation's `value` attribute:

       @Stateless
       @Local (value={Local1.class})
       @Remote (value={Remote1.class, Remote2.class})

2. Create the stateless session bean class.

   You can create a plain old Java object (POJO) and define it as a stateless session bean with the `@Stateless` annotation.

   Implement your remote interface, if used.

3. Implement your business methods.

   Note: A stateless session bean does not need a remove method.

4. Optionally, define lifecycle callback methods using the appropriate annotations.

   You do not need to define lifecycle methods: OC4J provides an implementation for all such methods. Define a method of your stateless session bean class as a lifecycle callback method only if you want to take some action of your own at a particular point in the stateless session bean's lifecycle.

   For more information, see "Configuring a Lifecycle Callback Method for an EJB 3.0 Session Bean".

5. Complete the configuration of your session bean (see "Using EJB 3.0 Session Bean API").