1

当使用祖先执行查询时,我尝试使用远程 api 并获得异常。

例外:

查询必须与包含的祖先键具有相同的应用程序 ID (app):query.app:'firtsAppId' != query.ancestor.app:'secondAppId'

其中 firtsAppId, secondAppId - 这是我在 appengine-web.xml 上的“远程”和“客户端”中的应用程序 ID

  • AppEngine SDK 1.7.4
  • 视窗 8 x64
  • jdk1.6.0_38 x64

下面的代码:

RemoteApiOptions options = new RemoteApiOptions().server(appId, 443).credentials(username, password);

installer = new RemoteApiInstaller();
installer.install(options);

DatastoreService service = DatastoreServiceFactory.getDatastoreService();

Entity parentEntity = new Entity("ParentEntity", 1);
parentEntity.setProperty("name", "parent");
Key parentKey = service.put(parentEntity);

Entity childEntity = new Entity("ChildEntity", 1, parentKey);
childEntity.setProperty("name", "child");
service.put(childEntity);

Query q = new Query("ChildEntity").setAncestor(parentKey);
Iterable<Entity> values = DatastoreServiceFactory.getDatastoreService().prepare(q).asIterable();
Iterator<Entity> i = values.iterator();

while (i.hasNext())
{
     Entity e = i.next();
     //some code
}

installer.uninstall();

堆栈跟踪:

java.lang.IllegalArgumentException: query must have same application id (app) as the contained ancestor key: query.app:'firtsAppId' != query.ancestor.app:'secondAppId'
    at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:33)
    at com.google.appengine.api.datastore.DatastoreApiHelper$1.convertException(DatastoreApiHelper.java:70)
    at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:94)
    at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:86)
    at com.google.appengine.api.datastore.FutureHelper.getInternal(FutureHelper.java:71)
    at com.google.appengine.api.datastore.FutureHelper.quietGet(FutureHelper.java:32)
    at com.google.appengine.api.datastore.QueryResultsSourceImpl.peekQueryResultAndIfFirstRecordIndexList(QueryResultsSourceImpl.java:161)
    at com.google.appengine.api.datastore.QueryResultsSourceImpl.loadMoreEntities(QueryResultsSourceImpl.java:104)
    at com.google.appengine.api.datastore.QueryResultsSourceImpl.loadMoreEntities(QueryResultsSourceImpl.java:91)
    at com.google.appengine.api.datastore.QueryResultIteratorImpl.ensureLoaded(QueryResultIteratorImpl.java:142)
    at com.google.appengine.api.datastore.QueryResultIteratorImpl.hasNext(QueryResultIteratorImpl.java:62)

上面的代码在本地和部署时都不起作用。

4

0 回答 0