GAE w / Objectify - 你可以查询一个HashMap吗? [英] GAE w/ Objectify - Can you query a HashMap?
问题描述
ofy()。load().type(MyClass.class).filter( hashMapfieldName,keyQueryinggFor)。list();
似乎并不适用于 hashMapfieldName
是一个 HashMap< String,String>
。我正在寻找找到 hashMapfieldName
包含某个键的实体。
就像嵌入类一样,Objectify将 Map< String,String>
转换为低级 EmbeddedEntity
对象,它是不可索引。但是,如果您@Index您的 Map
字段(或嵌入的类字段),Objectify将创建一个综合索引,允许您查询。
在你的例子后面,假设你有一个名为 hashMapfieldName
的Map字段,其中包含字符串key
到value
。此查询语法将返回具有该对的实体:
ofy()。load()。type(MyClass.class)。过滤器(hashMapfieldName.key,value);
如果您只是寻找关键存在,请尝试 filter(hashMapfieldName。 key!=,null)
。
In GAE, when using Objectify, can you query a HashMap? If so how would would you write it?
ofy().load().type(MyClass.class).filter("hashMapfieldName", "keyQueryinggFor").list();
Does not seem to work where the hashMapfieldName
is a HashMap<String, String>
. I am looking to find entities where hashMapfieldName
contains a certain key.
Just like embedded classes, Objectify converts Map<String, String>
to the low-level EmbeddedEntity
object, which is not indexible. However, if you @Index your Map
field (or embedded class field), Objectify will create a synthetic index that lets you query anyways.
Following your example, let's say you have a Map field named hashMapfieldName
containing the mapping of strings "key"
to "value"
. This query syntax will return entities that have the pair:
ofy().load().type(MyClass.class).filter("hashMapfieldName.key", "value");
If you are just looking for key existence, try filter("hashMapfieldName.key !=", null)
.
这篇关于GAE w / Objectify - 你可以查询一个HashMap吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!