Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

4 Implementing an EJB 3.0 Session Bean

This chapter explains how to implement an EJB 3.0 session bean, including:


Note:

In this release, OC4J supports a subset of the functionality specified in the EJB 3.0 public review draft. You may need to make code changes to your EJB 3.0 OC4J application after the EJB 3.0 specification is finalized and OC4J is updated to full EJB 3.0 compliance. For more information, see "Understanding EJB Support in OC4J".

There are no OC4J-proprietary EJB 3.0 annotations. For all OC4J-specific configuration, you must still use the EJB 2.1 orion-ejb-jar.xml file


For more information, see:

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:

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, local interfaces, or both 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").

Implementing an EJB 3.0 Stateful Session Bean

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

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


Note:

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

To implement an EJB 3.0 stateful session bean:

  1. Optionally, create one or more remote component interfaces, local interfaces, or both 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 stateful session bean class.

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

    Extend your remote interface, if used.

  3. Implement your business methods.

    To define a method of your stateful session bean class as a remove method, use the @Remove annotation.

  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 stateful 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 stateful 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").