Reattaching a serialized DataObject to a DataContext

From: Mike Kienenberger (mkienen..laska.net)
Date: Thu Apr 28 2005 - 16:31:03 EDT

  • Next message: Andrus Adamchik: "Re: Reattaching a serialized DataObject to a DataContext"

    On March 8th, Robert Zeigler wrote,
    > What is the preferred approach to attacher the data context? Simply call
    > setDataContext on the data object?

    Andrus replied,
    > I'd say yes, but then the same object may still be in the DataContext, so
    > you'll end up with a duplicate... So using someting along the lines of
    > writeReplace() / readResolve() will likely be more appropriate.

    I'm now in the situation where JSF is returning my serialized objects with
    the DataContext reset to null.

    I searched the cayenne source code for writeReplace and readResolve, and I
    don't find anything.

    Robert had also mentioned localObjects(), but that's just a wrapper for
    registeredObject().

    So I see my two possibilities as being:

            // If you don't know if the object is in the DataContext -- creates a new
    object
        attachedObject =
    (DataObject)dataContext.registeredObject(detachedObject.getObjectId());

    and

            // If you know the object is not in the DataContext -- probably should
    avoid this
            detachedObject.setDataContext(dataContext);

    Is there a better possiblity than registeredObject() I'm overlooking? It
    still creates a new object rather than just reattaching the existing one.

    Thanks,

    -Mike



    This archive was generated by hypermail 2.0.0 : Thu Apr 28 2005 - 16:29:13 EDT