Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-796

Deserialization of DataContext fails when useSharedCache is false

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.2 branch, 2.0 branch
    • 3.0M2
    • Core Library
    • None
    • JDK 1.5, Windows XP

    Description

      Sometimes while developing with Tomcat I get the exception below. This occurs when DataContext is serialized.

      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)

      Here is a little test to reproduce the error:

      package test;

      import test.cayenne.Employee;
      import java.io.ByteArrayInputStream;
      import java.io.ByteArrayOutputStream;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;
      import java.util.List;
      import org.objectstyle.cayenne.DataObjectUtils;
      import org.objectstyle.cayenne.access.DataContext;
      import org.objectstyle.cayenne.query.SelectQuery;

      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); }

      }
      }

      Note that if useSharedCache = true, then it works fine.

      Attachments

        Activity

          People

            andrus Andrus Adamchik
            sabob Bob Schellink
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: