First page Back Continue Last page Graphics

...Entity Beans


Notes:

As with session beans, removing an entity bean triggers an ejbRemove( ) method in the bean. But there are some important differences here between session and entity beans:
This ejbRemove( ) method belongs to the EntityBean interface rather than SessionBean.
It throws an additional exception, RemoveException. Use that exception to prevent the entity from being removed (deleted).
ejbRemove( ) is not the last EJB method in the life of an entity bean as it is with a session bean. The entity is removed from the database, but the bean instance is simply returned to the pool and may be populated later with data for a different entity.
This last difference has important implications for how you use these methods. In a session bean, ejbRemove( ) is typically used to clean up instance resources, such as socket or database connections. In an entity bean, another method (discussed below) serves that purpose. Only use ejbRemove( ) to check and handle related entity data.
The example on the next page illustrates a simple but typical use of ejbRemove( )...