You know, its been a while, but I think I've actually experienced this
behavior before... If I remember right, the DataContext hadn't
deserialized before the DataObject, and for some reason, it didn't
properly resolve the object graph to find it.
I wonder if its not a weird timing issue caused by a serializer bug?
On 9/26/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
> Hmm... This code will result in duplicate objects in the same context.
>
> But the default behavior should work in a generic clustering scenario
> - Cris is right about it - i.e. if your object serialization occurs
> as a consequence of session serialization. In this case DataContext
> is also serialized in the same sweep, so on de-serialization all
> objects are pulled back automatically and you don't have to
> "reconnect" them.
>
> Actually I never got back to investigating CAY-298, as this became
> less of a priority to me personally, but I assume in Tapestry
> problems occured when restoring objects stored explicitly via some
> other serialization mechanism that doesn't involve storing the
> DataContext...
>
> My solution for that (I haven't tried it yet) was to rely on thread
> DataContext during de-serialization and substitute deserialized
> object clone with an object from that DataContext using
> 'readResolve'. This would minimize the serialized footprint and
> maintain uniquing.
>
> I use the same approach (albeit custom-coded) in my web applications:
> entity name + int id + thread DataContext is all I need to get an
> object from request.
>
> Andrus
>
> On Sep 23, 2005, at 1:24 PM, Mike Kienenberger wrote:
>
> > What are others doing to handle reconnecting serialized DataObjects
> > back to a DataContext?
> >
> > My current situation is that JSF serializes all of my DataObjects
> > between requests, and I'm using this code to restore them. However, I
> > suspect this code doesn't properly handle the case where the data
> > context may change.
> >
> > Kevin's thread "CayenneDataObject#setDataContext()" has me worried
> > that I need to do more than what I'm currently doing.
> >
> > [In the code below, currentDataContext may or may not be the original
> > DataContext, although I think my dataContext has remained unchanged so
> > far.]
> >
> > public void reconnect(Object object)
> > {
> > if (null == object) return;
> >
> > if (false == (object instanceof DataObject))
> > throw new
> > IllegalArgumentException(object.getClass().getName() + " is not a
> > DataObject.");
> >
> > DataObject dataObject = (DataObject)object;
> >
> > if (null != dataObject.getDataContext()) return;
> >
> > dataObject.setDataContext(currentDataContext);
> >
> > EntityResolver entityResolver =
> > currentDataContext.getEntityResolver();
> > ObjEntity objEntity = entityResolver.lookupObjEntity
> > (dataObject);
> >
> > // initialize to-many relationships with a fault
> > Iterator it = objEntity.getRelationships().iterator();
> > while (it.hasNext()) {
> > ObjRelationship rel = (ObjRelationship) it.next();
> > if (rel.isToMany()) {
> > dataObject.writePropertyDirectly(rel.getName(),
> > Fault.getToManyFault());
> > Object relObject =
> > dataObject.readPropertyDirectly(rel.getName());
> > if (relObject instanceof List)
> > {
> > List relList = (List)relObject;
> > Iterator relObjectIterator = relList.iterator();
> > while (relObjectIterator.hasNext())
> > {
> > DataObject relDataObject = (DataObject)
> > relObjectIterator.next();
> > reconnect(relDataObject);
> > }
> > }
> > }
> > else
> > {
> > Object relObject =
> > dataObject.readPropertyDirectly(rel.getName());
> > if (relObject instanceof DataObject) reconnect
> > (relObject);
> > }
> > }
> > }
> >
> >
>
>
This archive was generated by hypermail 2.0.0 : Tue Sep 27 2005 - 08:39:24 EDT