According to the spec, what should the container do if a stateful session bean holds a non-null reference to non-serializable object (Socket, for instance) while passivating the bean? Any exception will be thrown? [ February 15, 2005: Message edited by: Keerthi P ]
hi, A session bean instance wont b passivated if it holds transaction context. Bean will throw exception if its holding a reference to an open socket connection.(system-level classes such as Thread, OutputStream and its subclasses, and Socket are not serializable).
If the variable(which is part of Session Beans conversational State)isn't serializable, then the serialization mechanism will throw an exception when it tries to serialize the variable. To avoid this, you can declare the variable to be transient.
Most probably, the NotSerializableException will be thrown.
P.S -> Will confirm it tomorrow though. I am feeling tooo sleepy today.
Regards,<br />Subhash Bhushan.
posted 15 years ago
OK. Here is what the spec has to say: The spec does not mandate the container to use Java's Serialization for passivating session beans. The container can choose to use it but need not necessarily have to. Of course, Passivation and Serialization are NOT the same because unlike serialization, passivation does not bother to reset 'transient' fields.
Therefore it is upto the container to decide what to do if an instance field in not serializable. The spec does not stipulate any rules regarding this. If such case should arise, the container may log the problem, throw SYSTEM exception and destroy the bean instance. It may also even choose to reset the non-serialiable field to null or whatever during activation. The spec generally discourages the use of such fields. It simply won't be restored. [ February 16, 2005: Message edited by: Keerthi P ]
SCJP, SCWCD, SCBCD, OCA J8
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!