• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ejbPostCreate() is for what?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. CMR fields cannot be initialized in the ejbCreate() section; they must be done in ejbPostCreate().
 
Saloon Keeper
Posts: 3946
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic