简体   繁体   English

GAE JAVA-按属性获取对象

[英]GAE JAVA - Getting Object by Property

I have Entity say, User { id (primary_key), phone } to be stored in Datastore. 我有实体说, User { id (primary_key), phone }要存储在数据存储区中。

While Retrieving same i can use getObjectById(User.class,id) to get object. 虽然检索相同,我可以使用getObjectById(User.class,id)来获取对象。 Is there way to get object with non-key property, say phone. 是否有办法获取具有非关键属性的对象,例如电话。

As per the documentation, Datastore creates index updates for Property "phone" too. 根据文档,数据存储区也会为媒体资源“电话”创建索引更新。 How do we use this index to get result? 我们如何使用该索引来获得结果?

You can simply use a JDO Query like following and Datastore will query on the non-key phone property (assuming you haven't set to to be unindexed ). 您可以像下面这样简单地使用JDO查询,并且数据存储区将在非按键电话属性上进行查询(假设您尚未设置为unindexed )。

q = pm.newQuery(User.class,"phone == '1234567890'"); q = pm.newQuery(User.class,“ phone =='1234567890'”);

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

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