A point of confusion for me:
1. ejbLoad(): Used to load data from persistence layer into THIS instance of an entity bean... hence PK obtained from the context.
2. ejbStore(): Used to persist data from THIS instance... hence PK obtained from member variable.
3. ejbCreate(): Data doesn't exist... so retrieve PK from say a PK generation utility, 'insert' data into the persistence layer and load THIS instance member variables with this data.
**** This is where the confusion comes in ****
4. ejbRemove(): Ed's book hints that this method is called to delete the data represented in the persistence layer by THIS instance (see point #6 page 165: BMP bean life-cycle). Logically then 'delete' data from the persistence layer should be identified by where PK = PK represented by member variable of THIS instance! The examples in the J2EE tutorial from the Sun website seems to support this approach. All of them use the member variable id to identify the dataset being deleted.
Yet the code example says that ANY instance of an entity bean may be used to delete some persistent data... hence always obtain the PK from the context! Both Ed's and Marinescu's example code follow this.
Which one is the right approach and why??
All the documentation I've read says that ejbRemove() is called when the active bean is pooled again and dissociated from any data instance. Which would again indicate that the PK for this method be obtained from a member variable.
If indeed the design of Entity beans required that the PK had to be obtained from the context in an ejbRemove() call, why not just design the method to be of the signature "public void ejbRemove(Object PK)"?
The ejbRemove() call follows the same logic as the ejbStore() method. Before these both are done a call to ejbLoad() is magically performed by the container, which fills the member variables. So, the usage of the member in the ejbRemove() is possible and you can use <b>any</b> pooled instance, because ejbStore() is called before.
... because ejbLoad() is called before.