"An example is the use of EJB context to acquire a bean's object interface. Until the bean is fully established, there is no way for a bean to acquire its own reference" -- Howard Kushner's book. Are there other examples? Should the relationship code be placed in this method? For Howard Kushner's example, why session bean has no such need?
You may think of 1. ejbCreate: a. INSERT INTO .... b. SELECT FROM ... - after insert EJB Container get DB table primary key for created instance 2. ejbPostCreate: a. UPDATE SET .... - EJB Container is updating relationships tables. For this EJB Container need PK he obtained in ejbCreate
Exam 1Z0-817: Upgrade OCP Java 6, 7 and 8 to Java SE 11 Developer Study Guide and Quiz
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
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad: