Objectify Query a attribute from an entity

天大地大妈咪最大 提交于 2019-12-24 19:46:18

问题


Is there a possible way to query a particular attribute from an entity using Objectify,

Lets say i have an Class entity with attributes {id,name,mail},how to filter only the mail attribute from the entity ? previously I was fetching the entire entity

Objectify ofy=ObjectifyService.begin();
Query<entity> q=ofy.query(entity.class);

and then retrieving the value q.getmail();

I am looking for filtering only *mail attribute from entity * in the query q ? please let me know how to do it.


回答1:


That's not how objectify works. You load the entire entity as a bean with a query. There's not really a synonym for SQL "select mail from entity where id=?" in objectify. What you can do is control which associated entities in the graphy are loaded from the datastore when you do a fetch (in objectify 4) using LoadGroups (https://code.google.com/p/objectify-appengine/wiki/BasicOperations#Load_Groups) but I don't think that's what you are asking.

That said, fetching 1 field and fetching an entire object take basically the same amount of time in appengine.



来源:https://stackoverflow.com/questions/11775317/objectify-query-a-attribute-from-an-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!