I could certainly use this too! You would think it would be easy… Ken Anderson CTO Amphora, Inc. Mobile: +1 914 262 8540
www.amphorainc.com <http://www.amphorainc.com/> On 2/15/17, 10:45 AM, "Hugi Thordarson" <h...@karlmenn.is> wrote: It can be useful in some cases—one example is if you want to be able to pass objects around in an API without triggering a DB fetch unless they are actually used. Cheers, - hugi > On 15. feb. 2017, at 15:28, Amedeo Mantica <amedeomant...@me.com> wrote: > > no worries, but I cannot understand your goal, why do you want to get the fault ? > >> On 15 Feb 2017, at 16:25, Hugi Thordarson <h...@karlmenn.is> wrote: >> >> Thanks Ken, but the immediate fetch performed by Cayenne.objectForPk is precisely what I’d like to avoid. >> >> Cheers, >> - hugi >> >> S: Amedeo, sorry about calling you “Amadeo” in my last post. I have been properly lambasted. >> >> >>> On 15. feb. 2017, at 15:20, Ken Anderson <ken.ander...@amphorainc.com> wrote: >>> >>> I do this: >>> >>> dataObject = (DataObject) Cayenne.objectForPK(getObjectContext(), MyEntity.class, oid); >>> >>> But it will do the fetch if it’s not already in cache. >>> >>> Ken >>> >>> Ken Anderson >>> CTO Amphora, Inc. >>> Mobile: +1 914 262 8540 >>> >>> >>> >>> www.amphorainc.com <http://www.amphorainc.com/> >>> >>> >>> >>> >>> On 2/15/17, 9:59 AM, "Hugi Thordarson" <h...@karlmenn.is> wrote: >>> >>> 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 <amedeomant...@me.com> wrote: >>>> >>>> may be you want invalidateObject ? >>>> >>>>> On 15 Feb 2017, at 14:15, Hugi Thordarson <h...@karlmenn.is> 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 >>>> >>> >>> >>> >>> Confidentiality Notice: This e-mail and accompanying documents contain confidential information intended for a specific individual and purpose. This e-mailed information is private and protected by law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, or distribution, or the taking of any action based on the contents of this information, is strictly prohibited. >> > Confidentiality Notice: This e-mail and accompanying documents contain confidential information intended for a specific individual and purpose. This e-mailed information is private and protected by law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, or distribution, or the taking of any action based on the contents of this information, is strictly prohibited.