FAQ
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

Search Discussions

  • Tomi N/A at Dec 18, 2006 at 3:27 pm

    2006/12/18, Øyvind Harboe <oyvind.harboe@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.
  • Tomi N/A at Dec 18, 2006 at 3:32 pm

    2006/12/18, Tomi N/A <hefest@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.
  • Øyvind Harboe at Dec 18, 2006 at 3:34 pm

    On 12/18/06, Tomi N/A wrote:
    2006/12/18, Øyvind Harboe <oyvind.harboe@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
  • Bryan Lewis at Dec 18, 2006 at 4:03 pm

    Ø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.
  • Øyvind Harboe at Dec 18, 2006 at 9:42 pm

    On 12/18/06, Bryan Lewis 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedDec 18, '06 at 3:06p
activeDec 18, '06 at 9:42p
posts6
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase