How to get an entity with the most recent date

Does anyone know how to get the lens object (with the most recent date)? I know how to make a request, but how to get the one with the latest date?

List<Transaction> fetched2 = ofy.query(Transaction.class).filter("someproperty", somepropertyvalue).order("date").list();

I could try to create a bubble, but I'm sure there is an easier way. thank

+5
source share
3 answers

You just need to add a minus before the “date” in your order:

List<Transaction> fetched2 = ofy.query(Transaction.class).filter("someproperty", somepropertyvalue).order("-date").list();

This should return you a list of transactions with the newest in the first position.

+7
source

, . ,

sample = ofy.query(Sample.class).filter( "propertyname", "propertyvalue" ).order( "+ date" ). List(). First();

sample = ofy.query(Sample.class).filter( "propertyname", "propertyvalue).order(" + date ")

0
source

All Articles