I understand that home and remote objects are network aware objects and thus should be Serializable. But the bean class itself is not network enabled. Then why are Bean classes Serialzable? All bean classes implement SessionBean or EntityBean interface, which extends EnterpriseBean interface which in turn extends Serializable interface.
Bean classes in case of Stateful Session beans are Seialized during passivation, but are they ever serialized in case of Stateless Session beans? In case of Entity Beans we always have to choose a persistent strategy (not necessarily Object Serialization) and persistent store so bean data is stored accordingly.
Very good question! I have no answer, but can add a few comments:
- SLSB cannot be passivated (since it does not make sense). See state diagram in section 7.8.1 of the EJB 2.0 spec.
- ejbPassivate() and ejbActivate() still has to be implemented for an SLSB. The reason must be that the STATEFUL/STATELESS information is put in the deployment descriptor, not in the Java code. (I have written SLSB with connections to legacy systems, and then I have implemented the two methods with 'throw new EJBException' to handle the case of very strange container design, or the case of someone making the bean stateful in the future.)
- Section 7.4.1 of the spec. gives a lot of details, but I suppose you have read it already.
- Activation and passivation of EntityBeans do not only include the persistent state, but also other instance variables not declared as transient. Or?
- "While the container is not required to use the Serialization protocol for the Java programming language
to store the state of a passivated session instance, it must achieve the equivalent result." Section 7.4.1.
The last note may be the reason why the EntityBean and SessionBean implements Serializable? But I still don´t understande why they must do so!!
EntityBeans can be passivated and activated (in between transactions). To be passivated they must be serialized.
I dont agree with the explaination that EntityBeans can be passivated and activated (in between transactions) requires them to be Serializable since according to Section 10.5.3 ejb specs,the ejbstore() is called when an EntityBean is passivated in the middle of transaction. So the data is always synchronized with the persistent store and not Serialized.