Thanks Amadeo, but I ended up creating a method that looks like this. It would
be nice to get some feedback on it, if I’m violating any Cayenne Commandments.
/**
* @return An existing object or fault if registered with the OC,
otherwise creates a new hollow object based on the given ObjectId.
*/
public static Persistent faultForObjectId( ObjectContext oc, ObjectId
objectId ) {
Persistent object = (Persistent) oc.getGraphManager().getNode(
objectId );
if( object == null ) {
ClassDescriptor descriptor =
oc.getEntityResolver().getClassDescriptor(objectId.getEntityName());
object = (Persistent) descriptor.createObject();
object.setPersistenceState(PersistenceState.HOLLOW);
object.setObjectContext(oc);
object.setObjectId(objectId);
oc.getGraphManager().registerNode(objectId, object);
}
return object;
}
Cheers,
- hugi
> On 15. feb. 2017, at 14:41, Amedeo Mantica <[email protected]> wrote:
>
> may be you want invalidateObject ?
>
>> On 15 Feb 2017, at 14:15, Hugi Thordarson <[email protected]> wrote:
>>
>> Hi all,
>> I need to get a fault for an ObjectId from an ObjectContext. How would I do
>> this?
>>
>> I don’t see any public API for this—the implementation of createFault in
>> CayenneContext seems to get me halfway there, but it will not return an
>> existing fault, only create new ones.
>>
>> Cheers,
>> - hugi
>