Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-02 |
|
![]() Previous |
![]() Next |
This chapter describes the various options that you must configure in order to use an EJB 3.0 session bean.
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 |
Table 5-1 lists these options and indicates which are basic (applicable to most applications) and which are advanced (applicable to more specialized applications).
For more information, see:
Table 5-1 Configurable Options for an EJB 3.0 Session Bean
Passivation is an Oracle-specific option that you configure using the EJB 2.1 orion-ejb-jar.xml
file.
For more information, see "Configuring Passivation".
Passivation criteria is an Oracle-specific option that you configure using the EJB 2.1 orion-ejb-jar.xml
file.
For more information, see "Configuring Passivation Criteria".
Passivation location is an Oracle-specific option that you configure using the EJB 2.1 orion-ejb-jar.xml
file.
For more information, see "Configuring Passivation Location".
You can specify an EJB 3.0 session bean class method as a callback method for any of the following lifecycle events (see "Using Annotations"):
Post-construct: a method called before the first business method invocation on the session bean and after OC4J performs any dependency injection.
Pre-destroy: a method called before OC4J removes the session bean. Typically, you use this method to release any resources that your session bean is holding.
Pre-passivate: a method called before OC4J passivates the session bean. Applicable to stateful session beans only. Use only if you need to close resources prior to passivation.
Post-activate: a method called immediately after OC4J reactivates a formerly passivated session bean. Applicable to stateful session beans only. Use only if you need to reopen resources after reactivation.
Note: Do not specify pre-passivate or post-activate lifecycle callback methods on a stateless session bean. |
The session bean class lifecycle callback method must have the following signature:
public void <MethodName>()
For more information, see "Callback Methods".
You can specify an EJB 3.0 session bean class method as a lifecycle callback method using any of the following annotations:
Example 5-1 shows how to use the @PostConstruct
annotation to specify EJB 3.0 stateful session bean class method initialize
as a lifecycle callback method.
You can designate one non-business method as the interceptor method for a stateless or stateful session bean (see "Using Annotations"). The method must have a signature of:
public Object <MethodName>(InvocationContext) throws Exception
For more information, see "Understanding EJB 3.0 Interceptors".
Example 5-2 shows how to designate a method of a session bean class as an interceptor method using the @AroundInvoke
annotation. Each time a client invokes a business method of this stateless session bean, OC4J intercepts the invocation and invokes the interceptor method myInterceptor
. The client invocation proceeds only if the interceptor method returns InvocationContext.proceed()
.
Example 5-2 @AroundInvoke in an EJB 3.0 Session Bean
@Stateless public class HelloWorldBean implements HelloWorld { public void sayHello() { System.out.println("Hello!"); } @AroundInvoke public Object myInterceptor(InvocationContext ctx) throws Exception { Principal p = ctx.getEJBContext().getCallerPrincipal; if (!userIsValid(p)) { throw new SecurityException( "Caller: '" + p.getName() + "' does not have permissions for method " + ctx.getMethod() ); } return ctx.proceed(); } }