Wednesday, December 27, 2006

EJB FAQs

What is ejbPostCreate() used for?

The usage of the ejbPostCreate() method has always been a point of confusion for many Enterprise JavaBeans (EJB) technology developers, but is very easy to explain. During initialization of an Entity Bean, the required ejbCreate() method of the bean is called and it's context is set. Finally the ejbPostCreate() method corresponding to the ejbCreate() method is called. During the call to ejbCreate() the bean knows nothing about itself or it's context. It is therefore unable to either pass a reference to itself, to another Entity bean, or even to access its own Primary key. In ejbPostCreate() the bean has access to its own remote interface and it's own Primary Key via the EntityContext and it's getEJBObject() and getPrimaryKey() methods. This is particularly useful for establishing relationships with other Entity Beans.

No comments: