| Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
EJB 3.0 greatly simplifies the development of stateful 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 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:
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})
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.
Implement your business methods.
To define a method of your stateful session bean class as a remove method using the @Remove annotation.
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".
Complete the configuration of your session bean (see "Using EJB 3.0 Session Bean API").