问题
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...
回答1:
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").
来源:https://stackoverflow.com/questions/10486635/how-to-sort-responses-in-objectify