【问题标题】:Sort Google App Engine对 Google App Engine 进行排序
【发布时间】:2013-06-20 18:27:37
【问题描述】:

我希望从 GAE 获取特定Merchant 下的约会列表,并根据约会时间进行排序 (dateLog):

PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Appointment.class.getName();  
query += " where merchant == '" + session.getAttribute("merchant") + "'";
query += " order by dateLog desc range 0,5";
List<Appointment> appointment = (List<Appointment>) pm.newQuery(query).execute(); 

但是,它返回错误,我已经检查/仔细检查了很多次,但无济于事。任何人都可以帮忙吗?我被难住了。

【问题讨论】:

  • 这是它在错误日志中所说的:The suggested index for this query is: &lt;datastore-index kind="Appointment" ancestor="false" source="manual"&gt; &lt;property name="merchant" direction="asc"/&gt; &lt;property name="dateLog" direction="desc"/&gt; &lt;/datastore-index&gt;

标签: java google-app-engine persistence gql


【解决方案1】:

您应该在应用程序的war/ 目录中的WEB-INF/datastore-indexes.xml 中指定建议的数据存储索引。 XML 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes  autoGenerate="true">
  <datastore-index kind="Appointment" ancestor="false" source="manual">
    <property name="merchant" direction="asc"/> 
    <property name="dateLog" direction="desc"/> 
  </datastore-index>
</datastore-indexes>

参考:https://developers.google.com/appengine/docs/java/config/indexconfig

【讨论】:

  • 您好 Nijin,感谢您回来。我的 WEB-INF 文件夹中不存在 datestore-indexes.xml,我用上面的代码创建了它,但它仍然不起作用.. 有什么想法吗?
  • 您是否重新部署了您的应用程序?在应用程序中使用新文件重新部署后,您现在是否在 App Engine 管理控制台的“索引”部分看到索引?
【解决方案2】:

如果您在上传到 App 引擎服务器之前测试 URL,则会自动生成索引文件。在开发服务器中运行并点击显示错误的 URL,它将生成文件,当您部署到 App 引擎服务器时,将构建索引和另一件事,您需要一些时间才能在数据存储索引中看到(构建和服务)在 Google App Engine 管理控制台中。

【讨论】:

    猜你喜欢
    • 2012-07-07
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    相关资源
    最近更新 更多