google-app-engine - 使用 Objectify 进行祖先查询不返回结果

标签 google-app-engine google-cloud-datastore objectify

我正在 appengine 上使用 objectify 3.1 并尝试执行祖先查询。我想获取某个对象的所有特定类型的子对象。下面是我的代码:

@Cached
@Entity
public class Car {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;

 private String make;
 private String model;

}

@Cached
@Entity
public class Tire {

@Id
public String keyName; 


@Parent Key<Car> car;

private String brand;
private String size;

}

我的查询是这段代码:

        List<Tire> list= ofy.query(Tire.class).ancestor(new    Key<Car(Car.class,carID))).list();

当我创建轮胎对象时,我使用此代码来设置关系:

        newTire.setCar(new Key<Car>(Car.class,Car.getID()));

我知道父关系存在,因为我可以在数据存储管理中查询它,并且它在解码的实体键中显示父关系:

Decoded entity key: Car: id=135172 > Tire: name=myCarUniqueID

这个查询总是返回 0 个结果,看起来我已经遵循了 objectify 网站上的所有最佳实践。任何帮助将不胜感激!

最佳答案

您的代码看起来没问题,因此唯一可能出错的是不存在的 carID

Objectify javadoc该网站上列出的实际上是主干版本,即即将推出的 Objectify 4。您需要查看的是 Objectify 3.1 javadoc :此版本在查询上有 fetch()

另外,@GenerateValuenot an Objectify annotation .

关于google-app-engine - 使用 Objectify 进行祖先查询不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10109089/

相关文章:

java - 异步对象化计数

google-app-engine - Google App Engine : Cron handler is called by cron, 但没有代码运行

python - 使用 google appengine 在 django-nonrel 中保存实体

http - 将应用上传到谷歌应用引擎时出现问题

python - 使用grpc和cloud-datastore时如何修复App Engine Flex中的AttributeError?

google-app-engine - Google App Engine Datastore 中模型类的 get_by_id 方法

python - python 中是否有任何方法或框架可以从 xml 创建对象模型?

google-app-engine - 如何使用 objectify-appengine 在数据库中找到最近点

android - 使用 Java 应用引擎的 GCM 服务器无法正常工作

python - Google Cloud Storage 中图像的服务 URL 是否会更改?