posted 20 years ago
Okay, let's start from the beginning:
The container starts, creates a few bean instances and puts them in the pool for later use. Those beans are in the "pooled state." The container calls setEntityContext() on each so they know about it.
After that, when the container needs one of the beans, it sets the bean's primary key to associate it with an actual entity bean that is stored in the database somewhere. Then the container calls ejbActivate() to let the bean know that it's being activated. The only data the bean has access to at that point is the primary key. The bean is now in the "ready state."
After that, the container calls ejbLoad to allow BMP beans to retrieve the rest of their data, or to notify CMP beans that the rest of the data values are stored in the bean. At this point, the client calls a bunch of methods and all the cool stuff EJB does.
At some point the client will be done with the bean. It may not be used for a while and the container wants to save some memory. At that time, the container will invoke ejbStore() to let a BMP bean store its data to a database or somewhere else, or to notify a CMP bean that its values have been stored in the database.
After that, the container will call ejbPassivate() to let the bean know that it is being passivated. At this point, it again only has access to the primary key. After ejbPassivate finishes, the bean is back in the "pooled state" to remain there motionless and useless until the container needs it again and the bean finds itself back in ejbActivate.
This is just a high-level view, mind you. There are other things that can happen in the lifecycle. For example, if there's a runtime exception, ejbPassive and ejbStore won't even get called. The container will just kill the instance.
Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED