我尝试使用远程api并在使用祖先执行查询时获取异常。
例外:
查询必须与包含的祖先具有相同的应用程序ID(app) key:query.app:'firtsAppId'!= query.ancestor.app:'secondAppId'
其中firtsAppId,secondAppId - 它是我的应用程序ID,位于appengine-web.xml上的'remote'和'client'
以下代码:
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)
上面的代码在本地和部署都不起作用。