The container invokes the ejbRemove method on an entity bean instance with container-managed persistence in response to a client-invoked remove operation on the entity bean�s remote home or remote interface.
So that means only when using a remote interface, ejbRemove should be invoked - this seems a bit silly though - I am using a local interface using a controller facade - I need the entity bean to perform checks on ejbRemove i.e. referential integrity, but it is not invoked when remove() is called from a local interface? Is this a gap in the EJB spec or am I missing something here?
Thanks, but the problem lies with the EntityBean ejbRemove() - this is almost like an event, that is fired when a client calls the remove method - now calling the remove from a remote interface will invoke ejbRemove, but calling the local interface remove does not invoke ejbRemove and I believe this is why the spec states "remote" interface.
I suppose the best place to encapsulate "pre-delete" behaviour is ejbRemove, but the container does not invoke it when remove() using a local interface?
Originally posted by Johann Evans: The EJB spec mentions: The container invokes the ejbRemove method on an entity bean instance with container-managed persistence in response to a client-invoked remove operation on the entity bean�s remote home or remote interface.
The above statement is present in section 14.1.3, and section 14 is titled "EJB 1.1 Entity beans with container-managed persistence". That's probably why only the remote interfaces are mentioned.
I searched in the specs but could not find anything. So still have no answer to your question. Its strange, I (or most people for that matter) would expect the same behaviour for local beans, but then you are saying it is not happening. Hope someone has an explanation. By the way, which application server are you using?
It would make no sense at all for remove to be invoked only by a remote client. The EJB 2.0 spec says:
10.7.8 Entity EJBLocalObject class The entity EJBLocalObject class, which is generated by deployment tools, implements the entity bean�s local interface. It implements the methods of the javax.ejb.EJBLocalObject interface and the local business methods specific to the entity bean. The implementation of the remove() method (defined in the javax.ejb.EJBLocalObject interface) must activate an instance (if an instance is not already in the ready state) and invoke the ejbRemove method on the instance.
The implementation of each local business method must activate an instance (if an instance is not already in the ready state) and invoke the matching business method on the instance.