简体   繁体   English

Java Google Appengine datastore.get在现有实体上引发EntityNotFoundException

[英]Java Google appengine datastore.get throws EntityNotFoundException on an existing entity

Looking for ideas on How could it be that I am getting an EntityNotFoundException when trying to get an entity that I know exists by its key. 寻找有关如何尝试通过键获取我知道的实体时出现EntityNotFoundException的想法。

屏幕快照显示了带有实体和异常的管理控制台

As you can see in the screenshot I have an entity of kind "Qualifier" that has an ID/Name of 99_999_9993#5678 but getting an exception saying "No entity was found matching the key: Qualifier("99_999_9993#5678")" 正如您在屏幕快照中看到的那样,我有一个类型为“ Qualifier”的实体,其ID /名称为99_999_9993#5678但出现了一个异常消息“找不到与密钥匹配的实体:Qualifier(“ 99_999_9993#5678”)”

I don't think that it is relevant but just for completeness...: The entity is created inside a transaction and also has an ancestor (Entity Group). 我不认为这是相关的,而只是为了完整性...:该实体是在事务内部创建的,并且具有祖先(实体组)。 The get request is a simple non transnational get based on a manually created key. get请求是基于手动创建的密钥的简单非跨国性get。

Any idea on why do I get this EntityNotFoundException instead of getting the entity ? 关于为何为什么要获取此EntityNotFoundException而不是获取实体的任何想法?

It turns out that what I though was not relevant was actually very relevant. 事实证明,尽管我不相关,但实际上却非常相关。 When I created the entity I created a key for its ancestor using the KeyFactory but when I was getting it I only used its own part of the key. 创建实体时,我使用KeyFactory为它的祖先创建了一个键,但是当我获取它时,我只使用了它自己的一部分。

As soon as I changed it to use 我一改使用

Key groupKey=KeyFactory.createKey(Kinds.Group, group_id);
Key key=KeyFactory.createKey(groupKey,Kinds.Qualifier, qualifier_id );

instead of 代替

Key key=KeyFactory.createKey(Kinds.Qualifier, qualifier_id );

It started returning my Entity as expected. 它开始按预期返回我的实体。

so basically its important to note that the Datastore Viewer ID/Name shows only the local part of the keyname, ignoring any indication of the fact that there is an ancestor (Entity Group)... 因此基本上需要注意的重要一点是,数据存储查看器ID /名称仅显示键名的本地部分,而忽略任何有关祖先(实体组)的事实的指示...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM