File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

when is an instance of a entity bean created??

prasad bhn

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

Joined: Oct 10, 2002
Posts: 1589
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.
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)
I agree. Here's the link:
subject: when is an instance of a entity bean created??
It's not a secret anymore!