On 12/18/06, Tomi N/A <[EMAIL PROTECTED]> wrote:
2006/12/18, Øyvind Harboe <[EMAIL PROTECTED]>:
> 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

Reply via email to