// load data
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Map<Key, Entity> resultMap = datastore.get(DatastoreUtil.withAllAncesterKeys(key));
EntityHierarchy hierarchy = new EntityHierarchy(
DatastoreUtil.convert(key), DatastoreUtil.convert(resultMap.get(key)));
while (key.getParent() != null) {
key = key.getParent();
hierarchy.put(DatastoreUtil.convert(key), DatastoreUtil.convert(resultMap.get(key)));
}
return hierarchy;
} catch (IllegalArgumentException e) {
// invalid key string