问题
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