What happens after the bean creates a database record but before the bean is fully initialized and associated with an EJB object? How can the bean complete post-creation setup that requires knowledge of its EJB object?
ejbPostCreate() is called by the container immediately after ejbCreate() once the bean is associated with an EJB object. It allows the bean to perform additional initialization using its newly created EJB object reference.
- Container calls
ejbPostCreate()afterejbCreate()succeeds - At this point, the EJB Object (proxy) has been created
- Bean can now call
ctx.getEJBObject()to get its proxy - Used to pass the proxy to other beans, reset transaction flags
- Same parameters as corresponding
ejbCreate()
- One
ejbPostCreate()required for eachejbCreate()defined - Called after bean is bound to an EJB object
- Can safely call
getEJBObject()here (not inejbCreate())
- Built from: ejbCreate(), Entity Bean
- Related: getPrimaryKey(), Entity Context
- Don’t perform database operations here—
ejbCreate()already inserted the record - Don’t assume the transaction is committed yet