Questions about ejbCreate and ejbPostCreate

Technote (FAQ)
Problem
Answers to questions on ejbCreate and ejbPostCreate
Solution
Q: When initializing the persistent fields of an entity EJB™ with different values in the ejbCreate and ejbPostCreate callbacks, the database contains only the values set in ejbCreate. Why is the EJB container overwriting the value in ejbPostCreate?

A: The method ejbCreate is called to allow an entity EJB to create its instance and initialize its persistent data. However, the method ejbPostCreate is called to allow the EJB instance to further initialize itself and take advantage of the fact that it is now fully initialized; for example, making use of the entityContext, the ejbObject, and so forth (which are not valid in ejbCreate).


Q: Why is it that when creating two instances of the same entity bean in succession, the first with 10 instance variables set, and the second with only 5, that the uninitialized instance variables in the second case have values from the previous create.

A: You must initialize the instance variables. If you do not initialize them, the instance can contain any values (for example: the EJB container does not initialize them) and by coincidence can retain the previous values. This is quite likely because the EJB container uses the same instance to service both the client requests.











Document Information

Product categories: Software, Application Servers, Distributed Application & Web Servers, WebSphere Application Server, EJB Container
Operating system(s): Multi-Platform
Software version: 3.5, 4.0, 5.0, 5.1, 6.0
Software edition: Edition Independent
Reference #: 1178162
IBM Group: Software Group
Modified date: 2004-08-30