• Post Reply Bookmark Topic Watch Topic
  • New Topic

about ejbcreate()

 
Shanthi Priya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when client invoke create() method in home interface this causes the container to invoke newInstance() on bean class to create new bean instance, next container calls setSessionContext() followed by ejbcreate().
correct me if i am wrong!

My question is
Q) can container call bean class newInstance() method from the home interface?
Q) whats purpose of setSessionContext() method and what will it return??
Q) If newInstance() method creates new bean instance then why ejbcreate???
 
Ankur Srivastava
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shanthi

Here are the answers to your questions

Q) can container call bean class newInstance() method from the home interface?
Ans. No, the EJB specs do not permit you to call the newInstance().
We need to call the create method on the home interface as the container creates the Object of the home interface and when you call the create method on the home interface the container intercepts your request. It creates an EJBObject. This EJB object is not just an instance of your bean class but it also has the logic for the various services which you have requested for from your container.

If you directly want to use the newInstance method() on the bean class you will have to write all the logic for transaction managment, caching etc, and thus you will loose the purpose of using EJB's. These are services provided by you EJB container and you therefore skip coding for these services when writing your bean code.

I hope this has answered your 3rd question also.

Q) whats purpose of setSessionContext() method and what will it return??
Ans. setters as such do not reurn anything. setSessionContext() will associate you bean with a session context. You can use this context to know about the beans current transactional state, its security state etc.

I hope this clears most of your doubts.

----
Ankur
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!