Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# 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
    }