【问题标题】:Objectify: sort results of a query ("no matching index found" error)Objectify:对查询的结果进行排序(“找不到匹配的索引”错误)
【发布时间】:2012-11-01 13:49:33
【问题描述】:

我在执行下面的查询的浏览器上收到此错误,但没有 ".order("position") 它可以工作(但结果显然没有排序)。

Uncaught com.google.web.bindery.event.shared.UmbrellaException: Exception caught: Server Error: no matching index found.
The suggested index for this query is:
    <datastore-index kind="Box" ancestor="false" source="manual">
        <property name="diagram_id" direction="asc"/>
        <property name="position" direction="asc"/>
    </datastore-index>

BoxDao.java

public List<Box> listFromDiagram(String diagramId)
{
    Objectify ofy = ObjectifyService.begin();
    // List of boxes of that diagram ordered by position asc
    Query<Box> q=ofy.query(Box.class).filter("diagram_id",diagramId).order("position");
    List<Box> results = q.list();

    return results;
}

Box.java

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Indexed;

@Entity
public class Box extends DatastoreObject{
    @Indexed private String boxId;
    @Indexed private String diagram_id;
    private String title;
    @Indexed private int position;
[...]
}

文件“datastore-indexes.xml”是空的...有什么想法吗?谢谢

【问题讨论】:

    标签: java gwt google-cloud-datastore requestfactory objectify


    【解决方案1】:

    您需要一个多属性索引(您正在按一个属性过滤并按另一个属性排序)。错误消息告诉您需要在 datastore-indexes.xml 中放入什么。有关概念性概述,请参阅:

    https://code.google.com/p/objectify-appengine/wiki/Concepts#Indexes

    我也建议您点击 Google 文档的链接。

    【讨论】:

    • 谢谢!这解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 2016-03-17
    • 2021-08-19
    • 2014-04-21
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多