| Can I assume that an ejbLoad has preceded ejbRemove? |
|
Is it allowed for a container to call ejbRemove on an entity bean with CMP without ever having called ejbLoad on the instance? Specifically, is it a valid state transition for an entity bean with BMP to go from "pooled" to "ready" with a call to ejbActivate and then immediately back to "pooled" with a call to ejbRemove, without ejbLoad being called by the container? ejbLoad would be called by the Container in the above scenario. The intent of the EJB specification is that the instance must be "loaded" before ejbRemove is called. Requiring the ejbLoad method is also necessary to make the BMP model consistent with CMP. Allowing the container not to call the ejbLoad would lead to an error-prone programming model for the developer of the ejbRemove method. This is because sometimes the instance would be "loaded" and sometimes it would not. Then an entity with BMP will need to be coded to only depend on the primary key in the entity context, specifically not assuming that its other instance variables (cached state) have been set. However, there is no guarantee that an ejbLoad callback is always performed before ejbRemove. For example, an instance may not receive an ejbLoad if the instance got to the "ready" state via the ejbCreate/ejbPostCreate transition. Here the ejbCreate will essentially load the bean, since it is required to set the bean's instance variables before returning. The bottomline is that the instance must be "loaded" before ejbRemove is called. In both cases, the container ensures that the instance variables are up-to-date before dispatching the ejbRemove method. This means that unless the container is certain that the instance variables are up-to-date, the container must load the CMP fields from DB and call ejbLoad before it calls ejbRemove.
|