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

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

我的数据存储区中有现有实体。我可以通过属性查询找到它管理控制台,例如:

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

还可以通过编码的 key 字符串查询它,例如:

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

但是,当我通过未编码的 key 查询实体时,找不到它:

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

从以前的查询中,我可以验证 key 是否正确,并且相同的查询适用于相同类型的其他实体。

当我尝试通过 JDO API 访问实体时,我遇到了相同的行为:

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

此代码会导致以下异常:

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

这是怎么发生的?我该如何解决这个问题并避免将来再次出现?

最佳答案

离线时我们发现 urlsafe key 字符串对添加了空格的用户名进行编码,就像编码 KEY('UserEntry','user@mail.com ') 一样。这似乎是程序中的输入验证错误。

关于java - Appengine 数据存储区无法通过未编码的 key 找到现有实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288987/

相关文章:

java - 如何使用gradle复制类文件夹中的资源文件?

google-app-engine - Google NDB : Best way to read child entities from an entity, 重复属性与常规查询?

python - CloudDataflow 不能使用 "google.cloud.datastore"包?

algorithm - 房屋之间的距离,Google Directions API 查询限制太低,需要更好的算法

Spring MVC 应用程序无处不在,但不在 Google App Engine 上

java - 关于使用 Clojure 在 Eclipse 上开发 GAE 应用程序的问题

java - org.datanucleus.store.query.QueryCompilerSyntaxException : Identifier expected at character 12 in "u.username== value"

java - 正则表达式和 RSS 源

java - 如何在 Spring Boot 中注入(inject) Clock.getInstance()?

java - 如何为窗口关闭事件设置操作命令?