How does an entity bean delete its database record when a client calls remove() on the EJB object? How does the bean know which record to delete when instances are pooled?
ejbRemove() is a container callback that deletes the entity’s database record. In BMP, the bean must call getPrimaryKey() to identify which record to delete, then execute a DELETE query.
- Client calls
proxy.remove()on EJB object - Container calls
ejbRemove()on the bean instance - In BMP: bean calls
ctx.getPrimaryKey()to get the entity ID - Bean executes
DELETEquery to remove the database row - After returning, bean goes back to the pool—data is gone
- Only deletes the database record, not the Java object itself
- Bean can be pooled and reused for different data after removal
- In BMP, developer writes DELETE logic
- In CMP, container auto-generates the DELETE
- Built from: Entity Bean, getPrimaryKey()
- Related: ejbCreate(), ejbLoad(), Bean-Managed Persistence
- Different from session bean
ejbRemove()—that deletes the bean from RAM, this deletes database data - Must call
getPrimaryKey()because bean instances are pooled and reused - No parameters are passed—bean’s identity must be queried from context