On May 18, 2006, at 10:58 AM, Tomi NA wrote:

Hmm...I'm sorry to hear that. The problem is, I have a panel and a
bean (presenter, model, if you will) and I bind them using jgoodies
binding. Some of the bean fields are cayenne DataObjects. I have these
kinds of panels all over the app, but I need to serialize just a
couple of them: the point is to save a part of the frame (panel)
state.

Ok, then serializaing the entire context is indeed inappropriate. Just serialize the objects (note that 'objectContext' is a transient field, so a serialized object won't drag a DC with it).

How should I go about serializing/deserializing such objects? All I
have at my disposal right now is a stream to which I can write to or
read from, depending on whether I'm serializing or deserializing. I'm
not clear on what happens when I write an object to such a stream, no
matter the fact I have a serialized DataContext.

A simple trick would be to use thread-bound DC and create "readResolve" method in a custom DO superclass that reattaches itself to the thread context (or rather returns a substitute object local to the current DC):

private Object readResolve() throws ObjectStreamException {
   DataContext dc = DataContext.getThreadDataContext();
   return dc == null ? this : dc.localObject(getObjectId(), this);
}

Andrus



Reply via email to