Passivation of stateful EJB's (in Weblogic) requires all attributes to implement serializable. Unforutnately, my attribute is an object that is declared as final and does not implement searializable.
I thought I could work around this problem by manually persisting/restoring the attribute when ejbPassivate or ejbActivate is called. Unfortunately I haven't worked out a way of persisting a non-serailizable object. Does anyone know how to solve this little bugger of a problem?
Any help is greatly appreciated.
This is just a thought, but could you create another class that is serializable and declare it a part of your bean. You could then populate this class with the variables of the final class during passivation, and repopulate your final class during activation
Why dont you have your final class implement serialzable. EJB is based on RMI and everything is marshalled/demarshalled. So you have to have serializable Objects only.
Thanks for your suggestions, but unfortunately they both don't solve my problem....
The object I'm trying to serialise is javax.mail.Session.
Good idea - but it won't work in this problem because javax.mail.Session has private attributes without setters/getters, so I can't restore the objects state.
Unfortunately it's not my class and is declared final, so I can't extend and implement serializable.
Set the member field to null on ejbPassivate() which is invoked by the container.
You can also declare the field transient.
The field won't be serialized, and you have to think of a way to eventually recreate the field on ejbPassivate().
If you really need to recreate the field in the ejbActivate and you can't find an acceptable solution than your class should not be a Stateful Session Bean, in the first place.
There are plenty of classes and solutions outside javax.ejb
The javax.mail.Session instance(or the javax.mail.Store) can be stored in JNDI or in the worst case a database and can be retrieved back in the ejbActivate event.
But can anyone give me a better solution than this ?
this is for testing..dont consider this please