posted 20 years ago
Howdy -- the main difference between entity beans and session beans with respect to getting a reference to the EJB Object is that for an entity bean, the Container cannot prepare the EJB Object until AFTER ejbCreate() returns. Because...
* The Container needs the primary key in order to make the EJB Object.
* The Container cannot know the primary key until *after* the ejbCreate() method runs (regardless of whether its BMP or CMP).
With Session beans, though, the Container already *has* all the information it needs to make an EJB Object for a bean *before* it calls ejbCreate() on the bean instance.
So, the difference in the lifecycle, and in fact the original reason why ejbPostCreate() is part of the Entity Bean API is because the Container needs the bean to determine its own primary key, then tell the Container (by returning from ejbCreate()) and THEN the Container can *read* the primary key and create the EJB Object. But the bean still needs a chance to finish its initialization (and possibly get a reference to its own EJB Object), so that's why part of an entity bean's *creation* includes a follow-up call to ejbPostCreate().
Before CMP 2.0, this last-chance-to-finish-initializing-yourself-and-get-a-ref-to-your-own-EJBObject was really the only important reason for having ejbPostCreate() as part of the Container callback on an entity bean. But as Nathaniel and Mikalai pointed out, with CMP 2.0, ejbPostCreate() is the place where you must initialize your CMR fields.
cheers,
Kathy