aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Session bean create method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Session bean create method." Watch "Session bean create method." New topic
Author

Session bean create method.

vivek kumar
Greenhorn

Joined: Sep 18, 2007
Posts: 13
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?
Makwana Deepak
Greenhorn

Joined: Aug 14, 2007
Posts: 6
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.

So enjoy...
If you are not agree please tell me.
vivek kumar
Greenhorn

Joined: Sep 18, 2007
Posts: 13
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)"
badri nath
Ranch Hand

Joined: Dec 21, 2005
Posts: 57
Hi Vivek,

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.
Makwana Deepak
Greenhorn

Joined: Aug 14, 2007
Posts: 6
Badri Nath Hello,

Is that the case.....

"Create method of EJBHome would only return the instance of the remote object but not the actual instance of the bean."

So you mean that it does not create object of actual bean when we ask container for the same, I am still not agree with your above mentioned statement can you please breife it more....

I would be glad to you if you can Badri nath.

Regards,
Makwana Deepak
vivek kumar
Greenhorn

Joined: Sep 18, 2007
Posts: 13
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
Makwana Deepak
Greenhorn

Joined: Aug 14, 2007
Posts: 6
Vivek Hi,

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.

Thanks & Regars Vivek,
Makwana Deepak.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session bean create method.