App Engine 数据存储 - 查询枚举字段
我使用 GAE(Java) 和 JDO 来实现持久性。
我有一个带有 Enum 字段的实体,该字段被标记为 @Persistent 并正确保存到数据存储中(如从开发控制台中的数据存储查看器观察到的)。但是,当我查询这些基于枚举值放置过滤器的实体时,它总是返回所有实体,无论我为枚举字段指定什么值。
我知道 GAE java 支持像基本数据类型一样持久保存枚举。但它是否也允许基于它们进行检索/查询?谷歌搜索无法向我指出任何此类示例代码。
细节:
我在执行之前打印了查询。因此,在两种情况下,查询看起来像这样 -
SELECT FROM com.xxx.yyy.User WHERE role == super ORDER BY key desc RANGE 0,50
SELECT FROM com.xxx.yyy.User WHERE role == admin ORDER BY key desc RANGE 0,50
尽管数据存储查看器显示一些用户的类型为“admin”,一些用户的类型为“super”,但上述两个查询都返回数据存储中的所有用户实体。
I am using GAE(Java) with JDO for persistence.
I have an entity with a Enum field which is marked as @Persistent and gets saved correctly into the datastore (As observed from the Datastore viewer in Development Console). But when I query these entities putting a filter based on the Enum value, it is always returning me all the entities whatever value I specify for the enum field.
I know GAE java supports enums being persisted just like basic datatypes. But does it also allow retrieving/querying based on them? Google search could not point me to any such example code.
Details:
I have printed the Query just before being executed. So in two cases the query looks like -
SELECT FROM com.xxx.yyy.User WHERE role == super ORDER BY key desc RANGE 0,50
SELECT FROM com.xxx.yyy.User WHERE role == admin ORDER BY key desc RANGE 0,50
Both above queries return me all the User entities from datastore in spite of datastore viewer showing some Users are of type 'admin' and some are of type 'super'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前,我用简单的整数常量替换了枚举。将此案例报告为 Google 应用引擎中的问题:http:// code.google.com/p/googleappengine/issues/detail?id=2927
For time being, I have replaced the Enums with simple integer constants. Reported this case as an issue in the google app engine : http://code.google.com/p/googleappengine/issues/detail?id=2927
对于除 String 或 int 之外的参数,我相信您需要使用 declareParameters 来代替。尝试这样的事情:
或者如果你想要更多类似 gql 的语法 -
For a parameter other than a String or an int, I believe you need to use declareParameters instead. Try something like this:
or if you want more gql like syntax -
声明查询参数时,您需要使用枚举的类名。
例如,如果您使用方法样式构建查询,并假设您的枚举名为
Role
并在User
类下声明,则可以执行如下操作:You need to use your enum's class name when you declare the query parameter.
For example, if you build your query using the method style, and assuming your enum is called
Role
and is declared under theUser
class, you can do something like the following: