Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
By associating an EJB 3.0 stateful session bean with EJB 2.1 home and component interfaces (see "Using Annotations"), you can adapt an EJB 3.0 stateful session bean so that an EJB 2.1 client can access it.
You can use this technique to manage the incremental migration of an EJB 2.1 application to EJB 3.0 or to give existing EJB 2.1 clients access to new development that you implement using EJB 3.0.
For more information on EJB 2.1 home and component interfaces, see: the following
To adapt an EJB 3.0 stateful session bean for an EJB 2.1 client, do the following:
Associate the EJB 2.1 home interfaces with the EJB 3.0 stateful session bean.
Use the @RemoteHome
annotation for remote home interfaces, and the @LocalHome
annotation for local home interfaces:
@Stateful @RemoteHome (value=Ejb21RemoteHome1.class) @LocalHome (value=Ejb21LocalHome.class) public class MyStatefulSB { ... }
Note:
You may associate a stateful session bean with at most one remote and one local home interface.Consider the requirements for supporting the home interface's create
methods.
For each create<METHOD>
in the home interfaces, implement an initialization method in your EJB 3.0 stateful session bean with the same signature (number, order, and type of arguments), and annotate the method with @Init
:
@Stateful @RemoteHome (value=Ejb21RemoteHome1.class) @LocalHome (value=Ejb21LocalHome.class) public class MyStatefulSB { private String message; private String name; ... // Corresponds to home interface method create() @Init public void initDefault() throws CreateException { this.message = "Default Message"; this.name = "Default Name"; } // Corresponds to home interface method createWithMessage(String) @Init public void initWithMsg(String message) throws CreateException { this.message = message; } // Corresponds to home interface method createWithName(String) // Use @Init attribute value to disambiguate createWithName(String) // from createWithMessage(String). @Init(value="createWithName") public void initWithName(String message) throws CreateException { this.name = name; } ... }
Initialization methods may have any method name. OC4J matches a home interface create<METHOD>
to a stateful session bean initialization method by signature. Alternatively, you can use @Init
attribute value
to explicitly specify the name of the home interface create<METHOD>
. This is useful when two or more home interface create<METHOD>
methods have the same signature.
Initialization methods are invoked after the post-construct life cycle method is invoked, if present (see "Configuring a Life Cycle Callback Interceptor Method on an EJB 3.0 Session Bean").
Associate the EJB 2.1 component interfaces with the EJB 3.0 stateful session bean.
Use the @Remote
annotation for remote component interfaces, and the @Local
annotation for local component interfaces:
@Stateful @Remote (value={Ejb21Remote1.class, EJB21Remote2.class}) @Local (value={Ejb21Local.class}) public class MyStatefulSB { ... }
Note:
You may associate a stateful session bean with one or more remote and local component interfaces.