How to sort responses in Objectify?

随声附和 提交于 2019-12-03 16:21:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!