This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes when is an instance of a entity bean created?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "when is an instance of a entity bean created??" Watch "when is an instance of a entity bean created??" New topic
Author

when is an instance of a entity bean created??

prasad bhn
Greenhorn

Joined: May 04, 2001
Posts: 28
1. before ejbCreate()
2. after ejbCreate()
3. after ejbPostCreate()
4.within ejbCreate()

Thank You.


prasad bhuvanam
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
Its created before ejbCreate().
First from the "does not exist" state the newInstance() is called which calls your Entity beans default constructor,
2) then its setEntityContext()(if needed)
3) then home and finder methods
4) then ejbCreate()
Look at the Entity bean life cycle, you should find all this there
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
The entity bean instance is *created* whenever the Container decides to make beans for the pool, but of course this is *always* before any Container callback methods are invoked. Just don't forget that ejbCreate() has NOTHING to do with entity bean *instance* creation.
So, a bean's first real *business method* might be ejbCreate() (invoked when the client calls create()), and that could happen before any other home or component interface methods.
If you're asking this for the exam, just be sure to keep the difference between *bean / entity* creation and bean *instance* creation. The bean/entity is created when the client calls create(). But the bean *instance* is created (which really means *instantiated* and given an entity context) when the Container chooses. A single bean instance might be associated with many, many entity bean creations. In other words, a single bean instance, once instantiated/created and placed into the pool, might come out of the pool over and over again to *create* new entity beans.
The real confusion is over the term *bean* vs. *instance*. (And the spec is sometimes a little loose with that.) A *bean* is a *realization of a real entity from the underlying persistent store*. That's why we can say that an entity *bean* survives a Container crash, even though the entity bean *instance* obviously does not survive. As long as it is still possible for an entity bean instance to be populated with a particular entity's data, that *bean* is said to exist.
We have the same issue with destruction that we have with creation... the *bean* can be deleted even though the bean *instance* just goes back to the pool. The *bean* deletion/removal is NOT tied to the bean *instance* removal. Bean removal is tied to the client calling remove() on that bean (or through a cascading delete set-up for a CMR relationship), but the bean *instance* removal is, once again, completely up to the Container's decision to remove a bean from the pool (by calling unsetEntityContext()) or because of a crash or because the bean throws a system exception.
cheers,
Kathy
p.s. if you haven't checked out the OO forum today... there's a promotion going on for "Dating Design Patterns". Yes, you read that right. Author Solveig Haugland has the inside gossip and details about what the Gang of Four were *really* doing...
(have fun)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: when is an instance of a entity bean created??
 
Similar Threads
Does ejbStore get called after ejbCreate in CMP
ejbPostCreate Method is it compulsory
At what stage, the life cycle of a CMP bean can be assumed to be started ?
Coffee Cream on EB - Mistakes/Doubts #3
ejbPostCreate() in EntityBean