But wait... there’s more! Entity beans have new home container callbacks, too

image with no caption

For any entity bean using container-managed persistence (CMP), you will always have at least seven container callbacks—all from the EntityBean interface implementation. You don’t have to have a create() method in your home, but if you do have create() methods, you must match each create() with not one but two methods: ejbCreate() and ejbPostCreate(). If you have home business methods, you must write a matching ejbHome<methodName> method in the bean class.

If you use bean-managed persistence (BMP), where you write your own database access code, you also must match each finder method with an ejbFind<whatever> method. Remember, the only method required in a home interface is findByPrimaryKey(). But in a CMP bean, you won’t put any finders in your bean class even though they’re in your home interface.

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.