Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort responses in Objectify?

I'm currently building an app for deployment to GAE, using Objectify 3.1. I am getting strange results when attempting to do a query with an order() clause.

My domain:


public class InvoiceLineItem
{
    private int units;

    private BigDecimal unitCost;
    private BigDecimal extendedCost;

    private String description;

    @Parent Key<Invoice> invoice;
}

I am attempting to gather all of the InvoiceLineItems associated with a given Invoice using the following:

ofy ().query (InvoiceLineItem.class).ancestor (invoiceKey).list ( );

In my test case, this works just fine, returning 2 rows as expected.

However, when I try to add a sort order to the above query, like so:

ofy ().query (InvoiceLineItem.class).ancestor (invoiceKey).order ("+description").list ();

I always get 0 results. I've tried changing the order direction, the field its ordering by, the location of the order () clause in the query, all to no effect. Can anyone see anything that I'm doing wrong here?

Thanks...

like image 861
Steve Avatar asked May 07 '12 17:05

Steve


1 Answers

There are a couple potential issues here:

  • The description field must be indexed
  • The description field must be less than 500 chars, because over 500 chars gets converted to a Text which is not indexable
  • Get rid of the +. It's either .order("description") or .order("-description").
like image 110
stickfigure Avatar answered Nov 06 '22 04:11

stickfigure