Skip Headers

# Creating a New Entity Bean and ejbCreate / ejbPostCreate Methods

Previous

Next

When you create a new entity bean, by default, the bean's life cycle can be thought of as follows:

1. `ejbCreate` method:

   After the insert, the EJB container retrieves the primary key allocated by the database for the created instance.

   For a relational project:

   1. `INSERT INTO ...`

   2. `SELECT FROM ...`

   For an EIS project:

   1. `Write object ...`

   2. `Find object ...`

2. `ejbPostCreate` method:

   The EJB container updates container-managed relationship (CMR) fields. The EJB container needs the primary key obtained in the `ejbCreate` method.

   For a relational project:

   1. `UPDATE SET ...`

   For an EIS project:

   1. `Write object ...`

However, if you have non-null foreign key constraints in your database, doing a data source modification after the `ejbCreate` method executes can cause problems. To get around this, some application servers (such as OC4J) allow you to create new objects after the `ejbPostCreate` method executes, and rely on the container to resolve the foreign key constraint.

For more information, see "Configuring a Descriptor With EJB Information".