问题
I am working google and engine and objectify, since for the last 3 hours i have been trying to write a distinct query in objectify. Can anyone tell me how to write a distinct query in objectify on a particular column?
Regards, Sreekanth
回答1:
Distinct only works with projection queries, which are not directly supported by Objectify yet. They are on the roadmap. Please star this issue: https://code.google.com/p/objectify-appengine/issues/detail?id=188
In the mean time, you can issue a low-level API query and use objectify's load().fromEntity() to convert the result set to POJOs.
回答2:
Objectify (5.0.5+) now supports projection queries and distinct operation.
ofy().load().type(Entity.class).project("field1").distinct(true);
回答3:
It's important to not that DISTINCT works only with projection queries and I don't believe Objectify currently supports them (it currently returns only whole entities). You can still use the low-level Datastore API to perform a projection query.
来源:https://stackoverflow.com/questions/23154817/distinct-using-objectify