tomcat - java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException -


what causes kind of error in tomcat?

severe: exception loading sessions persistent storage java.io.writeabortedexception: writing aborted; java.io.notserializableexception:    bean.projectareabean  @ java.io.objectinputstream.readobject0(objectinputstream.java:1333)  @ java.io.objectinputstream.readobject(objectinputstream.java:351)  @ java.util.arraylist.readobject(arraylist.java:593)  @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)  @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)  @ sun.reflect.delegatingmethodaccessorimpl.invoke(     delegatingmethodaccessorimpl.java:25) 

just implement serializable

if you're getting notserializableexception follows,

java.io.notserializableexception: bean.projectareabean 

then means class identified qualified name in exception message (which bean.projectareabean in case) not implement serializable interface while been expected code behind. fixing relatively simple, let class implement serializable interface.

package bean;  import java.io.serializable;  public class projectareabean implements serializable {     private static final long serialversionuid = 1l;      // ... } 

the serialversionuid field not necessary, recommended maintains binary compatibility between different versions of class , serialized representations of instances. when add later new serializable field class, you'd need change serialversionuid field (usually incrementing 1 sufficient) prevent problems during deserialization of instance of older version of class. ides eclipse offer option (re)generate serialversionuid value hash computed based on fields.

see also:


mark unserializable fields transient

if serializable class contains in turn field/property referencing instance of class can absolutely not made serializable, you'd need mark transient. way skipped during serialization of class.

private transient someobject thiswillnotbeserialized; 

you need understand after deserialization field become null. note class' constructor , initialization blocks not invoked during deserialization. if you'd have finer grained control on serialization , deserialization, override readobject() , writeobject() methods. can find concrete examples in below links:


why serialization?

as why need worry serialization, because java servlet containers tomcat require classes implement serializable whenever instances of classes been stored attribute of httpsession. because httpsession may need saved on local disk file system or transferred on network when servlet container needs shutdown/restart or being placed in cluster of servers wherein session has synchronized.

in order able save java objects on local disk file system or transfer them on network, have converted byte stream first (basically: byte[] or inputstream) , possible if class behind object implements serializable. serializable interface doesn't anything, it's merely marker interface.

see also:


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -