Re: Ordering objects by primary keys

"[email protected]" <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CAAOOpAP-Fmn2UFXW3yWif8fZigAhh8M0Br8HwQJg4m4vrJjfuw@mail.gmail.com>
It did work! 🀩

Thanks Nikita. πŸ™

Cheers,

Giulio Cesare


On Wed, Oct 27, 2021 at 7:46 PM Nikita Timofeev <[email protected]>
wrote:

> Hi!
>
> You could try to add "db:" prefix to the primary key name.
> Something like this: orderBy("db:ARTIST_ID")
>
> On Wed, Oct 27, 2021 at 8:14 PM [email protected]
> <[email protected]> wrote:
> >
> > Hello,
> >
> > I am try to run some BBD tests integrated with Cayenne (succesfully, so
> > far).
> > I am at the point where I can not fully specify the record/object to
> select
> > in the test script, and so I am trying to select the latest object
> > inserted, matching some lose criteria.
> >
> > Unfortunately, I don't have a generic "insertion date" in all my
> entities;
> > so the next best think I could think of, is to use the value of the PK
> > (generated using Postgres sequences) to sort the selected objects (DESC)
> > and picking the first match.
> >
> > To achieve this, I have tried with this code:
> >
> > String dbEntityName =
> > context.getEntityResolver().getObjEntity(entityName).getDbEntityName();
> > ImmutableList<Ordering> orderBy =
> >
> context.getEntityResolver().getDbEntity(dbEntityName).getPrimaryKeys().stream()
> > .map(attribute -> new Ordering(attribute.getName(),
> SortOrder.DESCENDING))
> > .collect(ImmutableList.toImmutableList())
> > ;
> > BaseDataObject latestInstance =
> > ObjectSelect.query(clazz).orderBy(orderBy).selectFirst(context);
> >
> > but I get the following error:
> > - Can't resolve path component: [{EntityName}.{primaryKeyFieldName}]
> >
> > I realize that {EntityName} and {primaryKeyFieldName} live in two
> separate
> > contexts (Entities vs DB); but I have no more ideas on how to progress.
> >
> > Does anyone have any suggestions on how to do this stunt?
> >
> > Cheers,
> > Giulio Cesare
>
>
>
> --
> Best regards,
> Nikita Timofeev
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.