cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: localObject() behavior
Date Tue, 11 Apr 2017 18:49:03 GMT
> Anyone know why making a local object copy of a NEW object will set the
> copy to HOLLOW which will try to trigger faults later?

This is a valid situation in case of nested contexts. If you use 'localObject' on an object
from a parent context, copying it to a child context, it will resolve from HOLLOW by checking
the parent.

Andrus


> On Apr 10, 2017, at 7:38 AM, Michael Gentry <blacknext@gmail.com> wrote:
> 
> I'm converting an application from 3.0 to 3.1 and was fixing all the
> localObject() calls to be the simpler version introduced in 3.1.  One thing
> I encountered was a utility method:
> 
>    public static <T extends CayenneDataObject> T copyToContext(T
> cayenneObject, DataContext dataContext)
>    {
>        T copiedObject =
> dataContext.localObject(cayenneObject.getObjectId(), cayenneObject);
> 
>        // The returned copy is HOLLOW, make the copy NEW if the original
> is NEW.
>        if (cayenneObject.getPersistenceState() == PersistenceState.NEW)
>            copiedObject.setPersistenceState(PersistenceState.NEW);
> 
>        return copiedObject;
>    }
> 
> I tried removing this utility method and just use the new localObject(),
> but exceptions (such as FaultFailureException) started being thrown.  (I
> won't even try to explain why so many local object copies of non-persisted
> objects are being used.)
> 
> Anyone know why making a local object copy of a NEW object will set the
> copy to HOLLOW which will try to trigger faults later?
> 
> Thanks,
> 
> mrg


Mime
View raw message