// serialization support private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // TODO: most of this should be in the superclass, especially the code // connecting // super transient ivars // read non-transient properties in.defaultReadObject(); // deserialize local snapshots cache if (!isUsingSharedSnapshotCache()) { DataRowStore cache = (DataRowStore) in.readObject(); objectStore.setDataRowCache(cache); } // CayenneDataObjects have a transient DataContext // because at deserialize time the datacontext may need to be different // than the one at serialize time (for programmer defined reasons). // So, when a DataObject is resurrected because it's DataContext was // serialized, it will then set the objects DataContext to the correct // one // If deserialized "otherwise", it will not have a DataContext. synchronized (getObjectStore()) { Iterator<?> it = objectStore.getObjectIterator(); while (it.hasNext()) { Persistent object = (Persistent) it.next(); object.setObjectContext(this); } } // ... deferring initialization of transient properties of this context // till first // access, so that it can attach to Cayenne runtime using appropriate // thread // injector. }