First page Back Continue Last page Graphics
Setting Context...
The set*Context( ) methods:
- First EJB methods in bean instance’s life
- Use to capture context object in an instance variable
- Use to acquire other instance resources
What resources might the bean acquire?
- Home objects of related beans
- JDBC connections
- Sockets to other servers
Notes:
The set*Context( ) method is called when the bean is created; it is the first EJB method called. This method lets the container pass the context object to the bean. The bean should save the reference context to an instance variable for later use. This method is also the place to connect to external resources that the bean instance will use.
Note that in the case of entity beans, setEntityContext( ) is called when the bean instance (not the entity it represents) is created.
(Again note the similarity to Java servlets. The javax.servlet.Servlet interface has an init( ) method that receives a ServletContext object; the servlet is supposed to store its reference in an instance variable for future use.)