You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by abhishek jain <ab...@gmail.com> on 2010/07/13 10:34:20 UTC

Session error while loading an object

Hi friends,
I am using tomcat 5.5 , struts 1.x and i encounter the following error:
I actually store the object in session and retrieve that(for a shopping cart
application), pl. advice what i can do to remove this error:

Exception loading sessions from persistent
storagejava.io.WriteAbortedException: writing aborted;
java.io.NotSerializableException: com.cart.Customer
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333)
       at
java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
       at
java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
       at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
       at
org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1416)
       at
org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:940)
       at
org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:394)
       at
org.apache.catalina.session.StandardManager.load(StandardManager.java:321)
       at
org.apache.catalina.session.StandardManager.start(StandardManager.java:637)
       at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4202)
       at
org.apache.catalina.core.StandardContext.reload(StandardContext.java:3056)
       at
org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:432)
       at
org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1278)
       at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1570)
       at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1579)
       at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1579)
       at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1559)
       at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.NotSerializableException: com.cart.Customer
       at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
       at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
       at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
       at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
       at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
       at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
       at
org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1492)
       at
org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:957)
       at
org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:517)
       at
org.apache.catalina.session.StandardManager.unload(StandardManager.java:463)
       at
org.apache.catalina.session.StandardManager.stop(StandardManager.java:667)
       at
org.apache.catalina.core.StandardContext.stop(StandardContext.java:4362)
       at
org.apache.catalina.core.StandardContext.reload(StandardContext.java:3050)
       ... 7 more



-- 
Thanks and kind Regards,
Abhishek jain

Re: Session error while loading an object

Posted by Peter Crowther <pe...@melandra.com>.
On 14 July 2010 08:02, abhishek jain <ab...@gmail.com> wrote:

> I just realized that i am having in the Cart object which i save in
> session,
> references of datasource and message resources.
> This is creating the problem as they i believe are not serializable,
> Is there any way of overcoming them.
>
> They're not serializable for a good reason - you shouldn't really be
keeping references to system resources between requests.  As you've found
out, the session can be serialized at any time, and it may be deserialized a
long time later - potentially even after the application has been
restarted.  At this point, the references to datasources and message
resources may no longer be valid.

Why are you keeping references to the datasource and message resources in
the Cart now?  Can you re-think your design of the Cart so that it keeps
only serializable data between requests?

- Peter

Re: Session error while loading an object

Posted by abhishek jain <ab...@gmail.com>.
On Wed, Jul 14, 2010 at 1:39 AM, Peter Crowther <peter.crowther@melandra.com
> wrote:

> On 13 July 2010 16:15, abhishek jain <ab...@gmail.com> wrote:
>
> > On Tue, Jul 13, 2010 at 2:11 PM, Peter Crowther <
> > peter.crowther@melandra.com
> > > wrote:
> >
> > > On 13 July 2010 09:34, abhishek jain <ab...@gmail.com>
> wrote:
> > >
> > > > I am using tomcat 5.5 , struts 1.x and i encounter the following
> error:
> > > > I actually store the object in session and retrieve that(for a
> shopping
> > > > cart
> > > > application), pl. advice what i can do to remove this error:
> > > >
> > > > java.io.NotSerializableException: com.cart.Customer
> > > >
> > >
> > > You need to make sure that com.cart.Customer (and anything else you
> store
> > > in
> > > the session) is serializable.
> > >
> > > - Peter
> > >
> >
> > Thanks Peter,
> > i will check but i get this error only at times, and not always.
> > Can this still be the cause of the problem.
> > thanks
> > abhishek
> >
>
> Yes.  It's happening because your webapp is being reloaded (are you
> changing
> some part of it?) and there are active sessions.  The sessions are
> serialised to persist them; then the webapp is restarted; then the sessions
> are deserialised.
>
> If there are no sessions at the time the webapp is restarted, the problem
> will not occur.
>
> - Peter
>


Thanks Peter for the info,
I just realized that i am having in the Cart object which i save in session,
references of datasource and message resources.
This is creating the problem as they i believe are not serializable,
Is there any way of overcoming them.
Pl. advice,
thanks
abhishek

Re: Session error while loading an object

Posted by Peter Crowther <pe...@melandra.com>.
On 13 July 2010 16:15, abhishek jain <ab...@gmail.com> wrote:

> On Tue, Jul 13, 2010 at 2:11 PM, Peter Crowther <
> peter.crowther@melandra.com
> > wrote:
>
> > On 13 July 2010 09:34, abhishek jain <ab...@gmail.com> wrote:
> >
> > > I am using tomcat 5.5 , struts 1.x and i encounter the following error:
> > > I actually store the object in session and retrieve that(for a shopping
> > > cart
> > > application), pl. advice what i can do to remove this error:
> > >
> > > java.io.NotSerializableException: com.cart.Customer
> > >
> >
> > You need to make sure that com.cart.Customer (and anything else you store
> > in
> > the session) is serializable.
> >
> > - Peter
> >
>
> Thanks Peter,
> i will check but i get this error only at times, and not always.
> Can this still be the cause of the problem.
> thanks
> abhishek
>

Yes.  It's happening because your webapp is being reloaded (are you changing
some part of it?) and there are active sessions.  The sessions are
serialised to persist them; then the webapp is restarted; then the sessions
are deserialised.

If there are no sessions at the time the webapp is restarted, the problem
will not occur.

- Peter

Re: Session error while loading an object

Posted by abhishek jain <ab...@gmail.com>.
On Tue, Jul 13, 2010 at 2:11 PM, Peter Crowther <peter.crowther@melandra.com
> wrote:

> On 13 July 2010 09:34, abhishek jain <ab...@gmail.com> wrote:
>
> > I am using tomcat 5.5 , struts 1.x and i encounter the following error:
> > I actually store the object in session and retrieve that(for a shopping
> > cart
> > application), pl. advice what i can do to remove this error:
> >
> > java.io.NotSerializableException: com.cart.Customer
> >
>
> You need to make sure that com.cart.Customer (and anything else you store
> in
> the session) is serializable.
>
> - Peter
>

Thanks Peter,
i will check but i get this error only at times, and not always.
Can this still be the cause of the problem.
thanks
abhishek

Re: Session error while loading an object

Posted by Peter Crowther <pe...@melandra.com>.
On 13 July 2010 09:34, abhishek jain <ab...@gmail.com> wrote:

> I am using tomcat 5.5 , struts 1.x and i encounter the following error:
> I actually store the object in session and retrieve that(for a shopping
> cart
> application), pl. advice what i can do to remove this error:
>
> java.io.NotSerializableException: com.cart.Customer
>

You need to make sure that com.cart.Customer (and anything else you store in
the session) is serializable.

- Peter