Deserialization of DataContext fails when useSharedCache is false
-----------------------------------------------------------------
Key: CAY-796
URL: https://issues.apache.org/cayenne/browse/CAY-796
Project: Cayenne
Issue Type: Bug
Components: Cayenne Core Library
Affects Versions: 1.2 [STABLE], 2.0 [STABLE]
Environment: JDK 1.5, Windows XP
Reporter: bob schellink
Assignee: Andrus Adamchik
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.
-- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
This archive was generated by hypermail 2.0.0 : Mon Jun 04 2007 - 05:55:53 EDT