• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

ejbPostCreate() is for what?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. CMR fields cannot be initialized in the ejbCreate() section; they must be done in ejbPostCreate().
 
Bartender
Posts: 3665
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic