Hi all,
I invoked a method on a stateless session bean from a client file and saw in the logs that the order in which the methods got called was:
1. setSessionContext
2. ejbCreate
3. <method I was trying to invoke>
My query is: Why does setSessionContext method get called before ejbCreate()? It is so because till we invoke ejbCreate(), EJB Context is not created. And ,moreover, when is the SessionContext object actually created?
Regards,
Alongian
Discussions
EJB programming & troubleshooting: Why does setSessionContext() get called before ejbCreate()
-
Why does setSessionContext() get called before ejbCreate() (7 messages)
- Posted by: sk kumar
- Posted on: August 29 2003 06:58 EDT
Threaded Messages (7)
- Why does setSessionContext() get called before ejbCreate() by BENMIRA Nabil on August 29 2003 09:35 EDT
- Why does setSessionContext() get called before ejbCreate() by Mushtaq Ahmed on September 01 2003 05:28 EDT
-
Why does setSessionContext() get called before ejbCreate() by sk kumar on September 02 2003 05:20 EDT
- Information about the client by Sankhadeep Bhattacharya on September 03 2003 04:31 EDT
-
Why does setSessionContext() get called before ejbCreate() by Ian Mitchell on September 03 2003 06:39 EDT
-
Why does setSessionContext() get called before ejbCreate() by sk kumar on September 04 2003 05:18 EDT
- Why does setSessionContext() get called before ejbCreate() by Ian Mitchell on September 04 2003 11:39 EDT
-
Why does setSessionContext() get called before ejbCreate() by sk kumar on September 04 2003 05:18 EDT
-
Why does setSessionContext() get called before ejbCreate() by sk kumar on September 02 2003 05:20 EDT
- Why does setSessionContext() get called before ejbCreate() by Mushtaq Ahmed on September 01 2003 05:28 EDT
-
Why does setSessionContext() get called before ejbCreate()[ Go to top ]
- Posted by: BENMIRA Nabil
- Posted on: August 29 2003 09:35 EDT
- in response to sk kumar
Hi kumar,
First, The motivation behind an EJBContext is to encapsulate the beans domain in one
compact object. Note that a baens status may change over the beans life cycle,
and thus this context object can dynamically change over time as well. At runtime,
the container is responsible for changing the context to reflect any status
changes, such as the bean becoming involved in a new transaction.
So for our example it's normal that the container calls setSessionContext() before
the ejbCreate() method (note that in your ejbCreate() method you can need to access your SessionContext!)
BENMIRA NABIL -
Why does setSessionContext() get called before ejbCreate()[ Go to top ]
- Posted by: Mushtaq Ahmed
- Posted on: September 01 2003 05:28 EDT
- in response to BENMIRA Nabil
Hi
The Container calls setSessionontext method to associate your bean with a session context.
A session context is u'r beans gateway to interact with the container, u'r bean can use session context
to query the container abt u'r current transactional state,u'r current security state..
where as ejb create is used to initialize u'r beans .
Mushtaq -
Why does setSessionContext() get called before ejbCreate()[ Go to top ]
- Posted by: sk kumar
- Posted on: September 02 2003 05:20 EDT
- in response to Mushtaq Ahmed
Thanks Mustaq and BENMIRA. I was going thru some book and found that setSessionContext is actually called before the bean(Referring to Stateless session beans only) goes in Pooled state(it is not attached to any EJB object till now) and ejbCreate() is called before beans go in Method-Ready state(when it is ready to serve a client). Now if my understanding is correct: SessionContext object can be used to gain information about the container, about the bean and about the client also. About the container and the bean I see no issues. But how can I gain info about the client using the SessionContext object when setSessionContext is invoked before the bean is actually attached to any EJB object? -
Information about the client[ Go to top ]
- Posted by: Sankhadeep Bhattacharya
- Posted on: September 03 2003 04:31 EDT
- in response to sk kumar
The getCallerPrincipal() method in the SessionContext can be used to get information about the caller .The method type is of java.security.Principal -
Why does setSessionContext() get called before ejbCreate()[ Go to top ]
- Posted by: Ian Mitchell
- Posted on: September 03 2003 18:39 EDT
- in response to sk kumar
But how can I gain info about the client using the SessionContext
> object when setSessionContext is invoked before the bean is
> actually attached to any EJB object?
You (i.e. the client) wouldn't. But the *bean* might need to make use of the SessionContext upon creation, and so it has to actually be there before ejbCreate is invoked. -
Why does setSessionContext() get called before ejbCreate()[ Go to top ]
- Posted by: sk kumar
- Posted on: September 04 2003 05:18 EDT
- in response to Ian Mitchell
Agreed Ian. Now, I do not have any doubts in why setSessionContext() is invoked before ejbCreate(). What I want to know is how actually a bean comes to know about the client it is servicing(through the EJB Object)? To extend it further, how does a bean actually gather information about the client. -
Why does setSessionContext() get called before ejbCreate()[ Go to top ]
- Posted by: Ian Mitchell
- Posted on: September 04 2003 11:39 EDT
- in response to sk kumar
The container is telling the bean about its client through the session context (getCallerPrincipal, isCallerInRole, getUserTransaction).