Google Cloud Datestore-无法在Objectify v5上使用游标

问题描述 投票:0回答:1

我正在尝试在Objectify v5上使用游标,但是在遵循该示例时,我抛出了异常。

我的代码:

import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.QueryResultIterator;

Query<IndicadorEntity> query = ofy().load().type(IndicadorEntity.class).limit(1000);
query.startAt(Cursor.fromWebSafeString("1"));
final List<IndicadorEntity> indicadorEntities = new ArrayList<>();
QueryResultIterator<IndicadorEntity> iterator = query.iterator();

while (iterator.hasNext()) {
      indicadorEntities.add(iterator.next());
}

并且我收到以下异常:

java.lang.IllegalArgumentException: Unable to decode provided cursor.
[INFO] GCLOUD:  at com.google.appengine.api.datastore.Cursor.fromWebSafeString(Cursor.java:115)

怎么了?我在Google上找不到这样的问题,我只是在这里按照示例进行操作。

谢谢。

google-cloud-platform google-cloud-datastore objectify datastore
1个回答
0
投票

问题是这样:

query.startAt(Cursor.fromWebSafeString("1"));

必须是这个:

query = query.startAt(Cursor.fromWebSafeString("1"));

Objectify的API以功能样式构建。中间查询对象是不可变的; startAt方法返回一个新的中间查询对象,该对象从该游标值开始,并且不会改变另一个对象的状态。

© www.soinside.com 2019 - 2024. All rights reserved.