简体   繁体   English

Appengine数据存储区无法通过未编码的密钥找到现有实体

[英]Appengine Datastore cannot find existing entity by unencoded key

I have existing entity in datastore. 我在数据存储区中有现有实体。 I can find it Admin Console by attribute query eg: 我可以通过属性查询找到Admin Console,例如:

SELECT * FROM UserEntry where email = 'user@mail.com'

and also query it by encoded key string, eg: 并且还通过编码的密钥字符串来查询它,例如:

SELECT * FROM UserEntry where __key__ = KEY('cy1hcHByIAsSCVVzZXJFbnRyeM')

However, when I query the entity by unencoded key, it is not found: 但是,当我通过未编码的密钥查询实体时,找不到:

SELECT * where __key__ = KEY('UserEntry','user@mail.com')

From former queries I can verify that the key is correct and the same query works for other entities of the same type. 从以前的查询中,我可以验证密钥是否正确,并且相同的查询适用于相同类型的其他实体。

I experience the same behavior when I try to access the entity via JDO API: 当我尝试通过JDO API访问实体时遇到相同的行为:

pm.getObjectById(UserEntry.class, "user@mail.com");

This code results in following exception: 此代码导致以下异常:

javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind UserEntry with key UserEntry("user@mail.com")

How did this happen? 这怎么发生的? How can I resolve this issue and avoid it in the future? 如何解决此问题并在将来避免使用它?

Off-line we discovered that the urlsafe key string encodes for a username with a space added, as if it encoded KEY('UserEntry','user@mail.com ') . 离线我们发现urlsafe密钥字符串为添加了空格的用户名编码,就好像它编码了KEY('UserEntry','user@mail.com ') That seems an input validation bug in the program. 这似乎是程序中的输入验证错误。

Is the email property your PK on the Entity? 电子邮件属性是您在实体上的PK吗? Because if it is not, querying for it doen not make sense. 因为如果不是,那么查询它就没有意义。 Once you post your first query with the email as a ordinary property, I assume that it's not repeated on your PK, so you can not query using it on Key(type,email). 一旦您将第一个查询与电子邮件作为普通属性发布,我认为它不会在您的PK上重复,因此您无法在密钥(类型,电子邮件)上使用它进行查询。

After getting the entity on admin console, click on key property to be certain that the email is part of the key. 在管理控制台上获取实体后,单击密钥属性以确保该电子邮件是密钥的一部分。

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

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