You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2006/12/18 16:05:40 UTC

Persistent properties in Tapestry & Cayenne => NPE sometimes

I'm struggling with a crash in our app and I believe I have understood
what is wrong.


- Using Tomcat
- Marking a Cayenne Data Object as a persistent Tapestry property will
cause it to be put into the servlet session
- Tomcat will then(whenever it feels like it, it seems) serialize my
Cayenne Data Object.
- Serializing a Cayenne Data Object works fine as a Cayenne Data
Object implements Serializable, except that the DataContext is nulled
out.
- Depending on whether or not Tomcat decided to serialize and
deserialize the Cayenne Data Object, I may or may not get an NPE when
trying to do method no the Cayenne Data Object's DataContext (via
getDataContext())

My Servlet superpowers are not quite sufficient to determine the
solution, but a couple of things come to mind:

- Create a non-serializeable wrapper object which has a reference to
the Cayenne Data Object.  This will stop Tomcat from trying to
serialize & deserialize my Cayenne Data Objects
- Somehow configure Tomcat not to try to serialize Cayenne Data Objects


If my understanding is correct, then this is *nasty*. The problem is
that this problem does not exist on Jetty(which is our development
environment) and only on certain Tomcat servers depending on
configuration. I prefer being broken all the time instead of
sometimes.

Clustring is an insane overkill for our purposes so I know pffft about
clustering issues.

-- 
Øyvind Harboe
http://www.zylin.com

Re: Persistent properties in Tapestry & Cayenne => NPE sometimes

Posted by Tomi N/A <he...@gmail.com>.
2006/12/18, Tomi N/A <he...@gmail.com>:

> The trick is to be able to attach it to the correct context, if you
> have multiple (as you probably do).
> Try using the DataContext you store in your session (if that's where
> you put it).

Oh, one more thing: obviously, you have to change your DataObject
superclass to your extended Class (say,
SerializableCayenneDataObject). You do that in the modeler, datamap
configuration, entity defaults settings group, custom superclass
field.

Cheers,
t.n.a.

Re: Persistent properties in Tapestry & Cayenne => NPE sometimes

Posted by Øyvind Harboe <oy...@zylin.com>.
On 12/18/06, Bryan Lewis <br...@maine.rr.com> wrote:
> Øyvind Harboe wrote:
> > Right now I'd like to stop the bleeding by configuring Tomcat not to
> > try to serialize my persistent Tapestry properties, but that appears
> > easier said than done....
> >
>
> That should be possible.  See for example:
> http://forum.java.sun.com/thread.jspa?threadID=772735&messageID=4401886
>
> We do that to run with tomcat session persistence disabled.  We have no
> need for it, no clustering or failover requirements.

Thanks! That did remove an error in the log, but ref. the posting I
just did, although the issue raised is a real one with our app the
getDataContext() returning null does not appear to be a
serialize/deserialize problem....

-- 
Øyvind Harboe
http://www.zylin.com

Re: Persistent properties in Tapestry & Cayenne => NPE sometimes

Posted by Bryan Lewis <br...@maine.rr.com>.
Øyvind Harboe wrote:
> Right now I'd like to stop the bleeding by configuring Tomcat not to
> try to serialize my persistent Tapestry properties, but that appears
> easier said than done....
>

That should be possible.  See for example:
http://forum.java.sun.com/thread.jspa?threadID=772735&messageID=4401886

We do that to run with tomcat session persistence disabled.  We have no
need for it, no clustering or failover requirements.




Re: Persistent properties in Tapestry & Cayenne => NPE sometimes

Posted by Øyvind Harboe <oy...@zylin.com>.
On 12/18/06, Tomi N/A <he...@gmail.com> wrote:
> 2006/12/18, Øyvind Harboe <oy...@zylin.com>:
> > I'm struggling with a crash in our app and I believe I have understood
> > what is wrong.
> >
> >
> > - Using Tomcat
> > - Marking a Cayenne Data Object as a persistent Tapestry property will
> > cause it to be put into the servlet session
> > - Tomcat will then(whenever it feels like it, it seems) serialize my
> > Cayenne Data Object.
> > - Serializing a Cayenne Data Object works fine as a Cayenne Data
> > Object implements Serializable, except that the DataContext is nulled
> > out.
> > - Depending on whether or not Tomcat decided to serialize and
> > deserialize the Cayenne Data Object, I may or may not get an NPE when
> > trying to do method no the Cayenne Data Object's DataContext (via
> > getDataContext())
> >
> > My Servlet superpowers are not quite sufficient to determine the
> > solution, but a couple of things come to mind:
> >
> > - Create a non-serializeable wrapper object which has a reference to
> > the Cayenne Data Object.  This will stop Tomcat from trying to
> > serialize & deserialize my Cayenne Data Objects
> > - Somehow configure Tomcat not to try to serialize Cayenne Data Objects
> >
> >
> > If my understanding is correct, then this is *nasty*. The problem is
> > that this problem does not exist on Jetty(which is our development
> > environment) and only on certain Tomcat servers depending on
> > configuration. I prefer being broken all the time instead of
> > sometimes.
> >
> > Clustring is an insane overkill for our purposes so I know pffft about
> > clustering issues.
>
> You can deserialize cayenne objects, it probably isn't that hard, even
> in a container environment. You just extend the CayenneDataObject
> class and override the readResolve() method like so:
>
>     protected Object readResolve() throws ObjectStreamException {
>      DataContext dc = ...; // your DataContext, probably in the session
>      return dc == null ? this : dc.localObject(getObjectId(), this);
>    }
>
> The trick is to be able to attach it to the correct context, if you
> have multiple (as you probably do).
> Try using the DataContext you store in your session (if that's where
> you put it).

I don't want my Cayenne Data Objects serialized into the session in
the first place....

Putting them in Tapestry Visit(which is not serializable) would fix
that. The Visit object then plays the role of the non-serializable
wrapper I described.

Right now I'd like to stop the bleeding by configuring Tomcat not to
try to serialize my persistent Tapestry properties, but that appears
easier said than done....


-- 
Øyvind Harboe
http://www.zylin.com

Re: Persistent properties in Tapestry & Cayenne => NPE sometimes

Posted by Tomi N/A <he...@gmail.com>.
2006/12/18, Øyvind Harboe <oy...@zylin.com>:
> I'm struggling with a crash in our app and I believe I have understood
> what is wrong.
>
>
> - Using Tomcat
> - Marking a Cayenne Data Object as a persistent Tapestry property will
> cause it to be put into the servlet session
> - Tomcat will then(whenever it feels like it, it seems) serialize my
> Cayenne Data Object.
> - Serializing a Cayenne Data Object works fine as a Cayenne Data
> Object implements Serializable, except that the DataContext is nulled
> out.
> - Depending on whether or not Tomcat decided to serialize and
> deserialize the Cayenne Data Object, I may or may not get an NPE when
> trying to do method no the Cayenne Data Object's DataContext (via
> getDataContext())
>
> My Servlet superpowers are not quite sufficient to determine the
> solution, but a couple of things come to mind:
>
> - Create a non-serializeable wrapper object which has a reference to
> the Cayenne Data Object.  This will stop Tomcat from trying to
> serialize & deserialize my Cayenne Data Objects
> - Somehow configure Tomcat not to try to serialize Cayenne Data Objects
>
>
> If my understanding is correct, then this is *nasty*. The problem is
> that this problem does not exist on Jetty(which is our development
> environment) and only on certain Tomcat servers depending on
> configuration. I prefer being broken all the time instead of
> sometimes.
>
> Clustring is an insane overkill for our purposes so I know pffft about
> clustering issues.

You can deserialize cayenne objects, it probably isn't that hard, even
in a container environment. You just extend the CayenneDataObject
class and override the readResolve() method like so:

    protected Object readResolve() throws ObjectStreamException {
     DataContext dc = ...; // your DataContext, probably in the session
     return dc == null ? this : dc.localObject(getObjectId(), this);
   }

The trick is to be able to attach it to the correct context, if you
have multiple (as you probably do).
Try using the DataContext you store in your session (if that's where
you put it).

Cheers,
t.n.a.