简体   繁体   中英

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.

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

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")"

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.

Any idea on why do I get this EntityNotFoundException instead of getting the entity ?

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.

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)...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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