Accordint to one book:- "The create() method is invoked by the client to get a reference to the component interface of a session bean. It does not necessarily mean that a bean instance will be created upon receiving this call. If the bean is a stateless session bean, the container may already have created some bean instances and may use one of those instances to service the method calls. Or the container may wait until the client invokes a business method before it creates a bean instance." My question is, if a bean instance is created when business method is called then what will be the value of remote component interface between create and before the business method is called. Will it be null?
Vivek Hello, Look at your following, last line in your quotes
"Or the container may wait until the client invokes a business method before it creates a bean instance."
Here how container can wait for business method unless and until client get reference of Remote ie. component interface. Any way container already put some bean ready in pool, and it keeps creating in case suppose all the bean in pool in use. When client calls create() of Home interface, here in application server until server has object of component interface it wan't give response to the client or it might be exception that server cannot create object.
So, the moral of the story what i feel is that above statement makes you confuse, however it might not be the case in reality because actual implementation is done by container.
Well, U mean to say that the flow will not procees till we successfully run create() method( or say some exception). I am not sure about it, what some of my friends told me is like this.. "When we call create method on home interface container will create an EJBObject and return the referecce of this EJBObject. Now when we call a business method on this EJBObject reference,then the actual bean will be create(If it is not in the pool)"
you have understood it right.. now dont confuse yourself. Refer the first post you have wrote. the container may already have created some bean instances and may use one of those instances to service the method calls. Now if it doesnt have one then its again said in your post that it would wait the container may wait until the client invokes a business method before it creates a bean instance.. Now coming to your question whether the EJBObject would be null. No it will not be null. When you actually make a call for the bean by invoking the business method from remote interface then the bean instance would be created if it cant find one in the pool. Create method of EJBHome would only return the instance of the remote object but not the actual instance of the bean.
Hi Deepak, Let me explain you. We have two entity on severe EJBObject and Actual Bean. Client can never access actual mean instance,it will always invoke method on EJBObject instance.When we call create method, an instance of EJBObject is creates and is returned to client. But this EJBObject is not attached to any Bean instance. When we call a business method then the container pull a bean insatce from pool and attach this bean instance with the returned EJBObject and call the business method. - Client call goes to EJBObject - Container pull a bean instacne and attach it to the EJBObject on which client has called a business method. - then this EJBObject instace delegate this methos to bean instance
Thank you very much, I got the exact idea of how the EJBObject is different from the actual bean, I was confident because i read somewhere that EJBObject is the actual bean, but after reading your explanation I came to know that it is the actual bean but it creates it when we actually call business methods on that.