Re: Getting fault or object

Andrus Adamchik <[email protected]> Sat, 25 Oct 2025 12:15:28 -0400
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
Hi Ricardo,

A rough equivalent used by Cayenne internally is this:

  ObjectId oid =3D ObjectId.of(entityName, "PK_COL_NAME", id);
  ClassDescriptor descriptor =3D =
context.getEntityResolver().getClassDescriptor(entityName);

  Persistent o =3D (Persistent) descriptor.createObject();
  o.setObjectContext(context);
  o.setObjectId(oid);
  o.setPersistenceState(PersistenceState.HOLLOW);

  context.getGraphManager().registerNode(oid, o);

Thanks,
Andrus


> On Oct 24, 2025, at 9:05=E2=80=AFAM, Ricardo Parada =
<[email protected]> wrote:
>=20
> Good morning,
>=20
> I=E2=80=99m looking for the equivalent of the following EOF code:
>=20
> var obj =3D EOUtilities.faultWithPrimaryKeyValue(editingContext, =
entityName, id);
>=20
>=20
> What I have so far is:
>=20
> var objClass =3D =
oc.getEntityResolver().getClassDescriptor(objEntityName).getObjectClass();=

> var obj =3D SelectById.query(objClass, id)
>        .localCache()
>        .selectOne(oc);
>=20
> But it seems to fetch the object the first time even though the object =
already exists in the object context.=20
>=20
> Thanks in advance,
> Ricardo Parada
>=20