Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Implementing the setSessionContext Method

You use this method to obtain a reference to the context of the bean. A session bean has a session context that the container maintains and makes available to the bean. The bean may use the methods in the session context to make callback requests to the container.

The container invokes setSessionContext method, after it first instantiates the bean, to enable the bean to retrieve the session context. The container will never call this method from within a transaction context. If the bean does not save the session context at this point, the bean will never gain access to the session context.

When the container calls this method, it passes the reference of the SessionContext object to the bean. The bean can then store the reference for later use.

Example 11-11 shows a session bean saving the session context in the sessctx variable.

Example 11-11 Implementing the setSessionContext Method

import javax.ejb.*;

public class myBean implements SessionBean {
   SessionContext sessctx;

   public void setSessionContext(SessionContext ctx) {
      sessctx = ctx;   // session context is stored in instance variable
   }
   // other methods in the bean
}