Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which is first created EJB Object or Bean Instance

 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After EJB Home getting create( ) call from client ( for Stateful Session Bean ),
i) who is creating bean instance and EJB Object i.e) container or EJB Home
ii) which is first created?
iii) how these two are associated
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything is explained in section 7.6 of the EJB 2.0 spec

A session bean instance�s life starts when a client invokes a create<METHOD> method on the session bean�s home interface. This causes the container to invoke newInstance on the session bean class to create a new session bean instance. Next, the container calls setSessionContext and ejbCreate<METHOD> on the instance and returns the session object reference to the client. The instance is now in the method ready state.


This means that the container first creates the session bean instance and then the session object and that the association between both is kept somewhere in the container.
 
Sankar Subbiramaniam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my view, the EJBObject is created between setSessionContext() and ejbCreate() method calls. Reason: getEJBEobject() is available in ejbCreate() but not in setSessionContext().
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to the Object Interaction Diagram given in HFEJB in chapter 4. The order will be clear :

1. Client calls home.create(). The create method is called on the home object
2. EJBObject instance is created
3. SessionContext instance is created
4. Bean instance is created (Bean constructor runs)
5. setSessionContext() runs
6. ejbCreate() runs
7. EJBObject stub is returned to the client.

Expect a question on this in the exam . You need to memorize the exact order.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who creates the bean instance and the EJBObject? The container or the Home object?

What's the difference between the 2? Not much. The container writes the home object code and instantiates it. So whether the home object has the code to create the bean and the EJBObject or the container creates these outside of the home object's code, it does not matter. It's also container dependent and varies from vendor to vendor. In any case, it's the container's magic. How it implements the magic - through the home object or outside of it and how it associates the bean and EJBObject- you are not supposed to worry or know
 
Mani Venkatachalam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Per page No.94 (chapter 2) of HFEJB,

step 5. the bean is created
step 6. The EJBObject is made

Per page No. 178 (chapter 4) of HFEJB,

3. EJBObject is made
4. the bean is created

Both scenarios are referring to Stateful session beans. I know chapter4 explanation is right. Any idea why it was mentioned differently in chapter2
 
Sankar Subbiramaniam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Description in Page 94 is wrong. Refer to errata: HFEJB Errata
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic