问题
I tried to use remote api and get exception, when execute query with ancestor.
Exception:
query must have same application id (app) as the contained ancestor key: query.app:'firtsAppId' != query.ancestor.app:'secondAppId'
where firtsAppId, secondAppId - it's my app ids in 'remote' and 'client' on appengine-web.xml
- AppEngine SDK 1.7.4
- Windows 8 x64
- jdk1.6.0_38 x64
Code below:
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();
StackTrace:
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)
The code above doesn't work both locally and deployed.
来源:https://stackoverflow.com/questions/14714735/remote-api-gae-ancestor-query