Java Google应用程序引擎通过密钥获取对象

Java Google应用程序引擎通过密钥获取对象,java,google-app-engine,jakarta-ee,persistence,Java,Google App Engine,Jakarta Ee,Persistence,我无法通过id获取持久化对象。我遇到了一个错误: com.google.appengine.api.datastore.EntityNotFoundException: No entity was found matching the key: CNG("T78") 我按如下方式将对象持久化到数据存储: Key cngKey = KeyFactory.createKey("CNG", jsonCNG.cNGID); Entity cngEntity = new Entity("CNG", cn

我无法通过id获取持久化对象。我遇到了一个错误:

com.google.appengine.api.datastore.EntityNotFoundException: No entity was found matching the key: CNG("T78")
我按如下方式将对象持久化到数据存储:

Key cngKey = KeyFactory.createKey("CNG", jsonCNG.cNGID);
Entity cngEntity = new Entity("CNG", cngKey);
cngEntity.setProperty("cng_name", jsonCNG.cNGName);
cngEntity.setProperty("cng_type", jsonCNG.cNGType);
cngEntity.setProperty("cng_content", cng);
这里cng是一个json字符串。我用一个字符串设置键:cNGID。我正在尝试使用相同的id获取对象

Key cngKey = KeyFactory.createKey("CNG", "T78")

并最终得到上述错误。

您似乎没有将其保存到数据存储中

Datastore.put(cngEntity);
构造函数正在使用种类和父键定义实体。然后,当您尝试检索它时,您不提供父密钥:
KeyFactory.createKey(“CNG”、“T78”)
。这不起作用-您必须在not上的两个位置提供父密钥

注意-定义实体组时使用定义实体父级,而实体组在使用事务时又非常重要。你可能不想那样


相反,您应该只使用
newentity(cngKey)

实际上,我将它保存到数据源。对不起,代码丢失了。