cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Serialization of datacontext
Date Mon, 04 Jun 2007 09:26:41 GMT
Could you please open a bug report? We'll need to do some testing to  
settle on the best strategy (I am leaning towards not serializing the  
local DataRowStore at all, and rebuilding it on deserialization  
instead).

Thanks
Andrus

On Jun 4, 2007, at 11:46 AM, bob wrote:

> Hi
>
> I debugged this a bit and notice the following:
>
> on DataContext serialization the following code is executed in  
> writeObject(ObjectOutputStream)
>
>         ...
>         // Serialize local snapshots cache
>         if (!isUsingSharedSnapshotCache()) {
>             out.writeObject(objectStore.getDataRowCache());
>         }
>         ...
>
> So if useSharedCache is false, the ObjectStore's DataRowStore is  
> also serialized.
>
> DataRowStore's reference to EventManager is transient and not  
> serialized. So upon deserialization, when DataRowStore is read back  
> in, the EventManager is null and this caused the exception below.
>
> What is the best way to fix this? EventManager should not be  
> transient? Or a new EventManager should be created in  
> DataRowStore.readObject(ObjectInputStream)?
>
> regards
>
> bob
>
> bob wrote:
>> 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
>
>


Mime
View raw message