• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of ejbPostCreate

 
rajareddy annavaarm
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the the differernt between ejbCreate() and ejbPostCreate() .when we will use those methods.what is their purpose?
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a create() method is invoked on the home interface of an Entity Bean, EJB container invokes the corresponding ejbCreate() method. For each ejbCreate() method, you must write an ejbPostCreate() method in the entity bean class. The EJB container invokes ejbPostCreate immediately after it calls ejbCreate().In entity beans we do not have an EJBObject during the execution of ejbCreate(). However, we do have an EJBObject by the time ejbPostCreate() is executed. The ejbPostCreate() method gives us a chance to do extra initialization after the CMP fields are initialized, but before the entity bean is used by other beans. We can't accesss getPrimaryKey() and getEJBObject() methods of EntityContext in ejbCreate(), we can do it in ejbPostCreate(). In entity bean, ejbCreate() method only creates a new record in underlying database, but primary key is not associated with that object, ejbPostCreate() method allows the ejbObject to associate it with Primary Key generated.

Hope this help!!


Thanks,
Mahesh

-----------
SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - In Progress
 
rajareddy annavaarm
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for giving me reply.

i heard we can use ejbPostCreate() method for CMR.is it right?if so how?
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To set up the CMR fields during the creation of a bean, sometimes we might need primary key and we can not get it in ejbCreate method. And also we can not invoke methods like getEJBObject(), getEJBLocalObject(), or getPrimaryKey() in ejbCreate. So we use ejbPostCreate method to set the values of cmr-fields to complete the initialization of the entity bean instance.


Thanks,
Mahesh

-----------
SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - In Progress
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic