Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-02 |
|
Previous |
Next |
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 |
For more information, see:
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:
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})
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.
Implement your business methods.
Note: A stateless session bean does not need a remove method. |
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".
Complete the configuration of your session bean (see "Using EJB 3.0 Session Bean API").
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, 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})
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, use 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").