Serialization of datacontext

From: bob (sabob..mail.com)
Date: Thu May 24 2007 - 02:41:45 EDT

  • Next message: Steve Wells: "Re: Obtaining DataContext in ZK"

    Hi all

    Using cayenne 1.2.3 and jdk 1.5 on Windows XP.

    Sometimes while developing with Tomcat I get the following exception.
    Seems to happen on serialization of DataContext along with the session.
    Below the exception is a little test class to reproduce this. Note that
    if useSharedCache = true, then there is no exception. Should I open a
    JIRA issue or is this expected behavior?

    Exception in thread "main"
    org.objectstyle.cayenne.CayenneRuntimeException: [v.1.2.3 May 6 2007]
    Commit Exception
    org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1290)
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1166)
    test.SerializeDCTest.main(SerializeDCTest.java:29)

    Caused by: java.lang.NullPointerException
    org.objectstyle.cayenne.access.DataRowStore.sendUpdateNotification(DataRowStore.java:709)
    org.objectstyle.cayenne.access.DataRowStore.processSnapshotChanges(DataRowStore.java:574)
    org.objectstyle.cayenne.access.DataDomainFlushAction.postprocess(DataDomainFlushAction.java:278)
    org.objectstyle.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:178)
    org.objectstyle.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:846)
    org.objectstyle.cayenne.access.DataDomain$2.transform(DataDomain.java:817)
    org.objectstyle.cayenne.access.DataDomain.runInTransaction(DataDomain.java:872)
    org.objectstyle.cayenne.access.DataDomain.onSync(DataDomain.java:814)
    org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1262)

    package test;

    public class SerializeDCTest {

         public SerializeDCTest() {
         }

         public static void main(String[] args) {
             //boolean useSharedCache = true; //works
             boolean useSharedCache = false;
             DataContext context =
    DataContext.createDataContext(useSharedCache);
             context = serializeDC(context);
             Employee emp = (Employee) DataObjectUtils.objectForPK(context,
    Employee.class, 740);
             emp.setFirstname("test" + Math.random());
             context.commitChanges();
         }

         public static DataContext serializeDC(DataContext dc) {
             try {
                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
                 ObjectOutputStream oos = new ObjectOutputStream(bos);
                 oos.writeObject(dc);

                 ByteArrayInputStream is = new
    ByteArrayInputStream(bos.toByteArray());
                 ObjectInputStream ois = new ObjectInputStream(is);
                 DataContext result = (DataContext) ois.readObject();
                 return result;

             } catch (Exception ex) {
                 throw new RuntimeException("DataContext serialization
    failed", ex);
             }
         }
    }

    kind regards

    bob



    This archive was generated by hypermail 2.0.0 : Thu May 24 2007 - 02:42:55 EDT