Hi all

Using Cayenne 1.2.2, jdk5.

In my previous post when the "use shared cache" is false in the modeler and one were to programmatically set it to true, a nullpointer would be thrown. This was fixed in the meantime, thanks Andrus!

In my playing around with Cayenne options I ran into another exception awhile back. In the modeler under cache configuration the "use shared cache" is now enabled.

If one were to programmatically set the useSharedCache to false, AND the datacontext is somehow serialized which might happen in say a servlet container, the exception below is thrown. Here is the code to reproduce this exception.

public static void main(String[] args) {
   //boolean useSharedCache = true; //still works even after serializing
   boolean useSharedCache = false;
   DataContext context = DataContext.createDataContext(useSharedCache);
   context = serializeDC(context); //serialize and deserialize the dc
Employee emp = (Employee) DataObjectUtils.objectForPK(context, Employee.class, 200);
   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);
  }
}

Here is the stacktrace:

Exception in thread "main" org.objectstyle.cayenne.CayenneRuntimeException: Commit Exception
org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1290)
org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1166)
test.SerializeDC.main(SerializeDCTest.java:27)


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)

PS: I have tried for awhile now to reproduce the above error for a easy test case, but did not realize the above problem came about only after a serialization of the datacontext. This was until Marc Gabriel-Willem mentioned he had problems after serialization.

kind regards

bob


Reply via email to