Originally posted by Joe Nguyen:
I wonder how the container implements this. All ordinary objects are the same since they are created by invoking the empty constructor. There are many create() methods, each of which takes different parameters. After container invoking ejbCreate(String s), it creates bean instance A. And after the container invoking ejbCreate(String s1, String s2), it creates bean instance B.
You are talking about stateful session beans here. The container creates the instance before giving the bean its 'beanness'. The order by which the container creates a SFSB is: constructor, setSessionContext, ejbCreate
The container gives actually birth to a bean from an object (meaning that the bean passes from the 'Does not exists state, to the 'method ready state') through the setSessionContext (it tells the container - 'Listen, I'm giving to you something precious, something unique: this is the only 'red phone' you will have during your lifetime to call me if you need, so don't miss it'), and through the ejbCreate (with parameters if necessary), where the container links the EJBObject, the bean's context and the bean instance together. A bean has got some priviliges that an ordinary object hasn't. And those are granted thanks to the context, through which a 'fully qualified bean' can access things like a reference to its EJBObject and EJBHome, query the container about security info related to its client, get a UserTransaction object onto which invoking methods (only for BMT), access its special JNDI environment (from which, it can lookup useful info, like environment entries, resource manager connection factories, etc.), access other bean's methods, do transaction-related things for CMT).
All of those are things that an ordinary object can't do, and this is what you're paying for (the services offered by your EJBContainer provider).
[ August 07, 2004: Message edited by: Marco Tedone ]