I want to fetch distinct multiple columns from Google app engine Datastore in endpoint
class. For that i am using below code but problem is that if i try to fetch only single column then only it works properly and returns DISTINCT data. If i try to fetch multiple columns then DISTINCT
doesn't work and it returns all records without any effect of Distinct query. I don't know what is wrong with my code. Please suggest any solution and guide me where i am going wrong. Thank you.
我想从端点类中的Google应用引擎数据存储区中获取不同的多个列。为此,我使用下面的代码,但问题是,如果我尝试只获取单列,那么只有它正常工作并返回DISTINCT数据。如果我尝试获取多列,那么DISTINCT不起作用,它返回所有记录而没有任何Distinct查询的影响。我不知道我的代码有什么问题。请建议任何解决方案,并指导我在哪里出错。谢谢。
Code:
码:
@SuppressWarnings({ "unchecked" })
@ApiMethod(name = "getDistinctFollow", httpMethod = HttpMethod.GET, path = "userendpoint/userName_fk3")
public ObjectListContainer getDistinctFollower(
@Named("followName") ArrayList<String> lstFollower,
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Object[]> lstNames;
List<String> lstString;
ObjectListContainer object;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select distinct f.uFullName,f.uUrl from UMaster f where f.uName in (:followName)");
query.setParameter("followName", lstFollower);
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
lstNames = (List<Object[]>) query.getResultList();
cursor = JPACursorHelper.getCursor(lstNames);
if (cursor != null)
cursorString = cursor.toWebSafeString();
lstString = new ArrayList<String>();
for (Object obj[] : lstNames) {
lstString.add(obj != null ? obj[0].toString() : null);
lstString.add(obj != null ? obj[1].toString() : null);
}
object = new ObjectListContainer();
object.setObjectsList(lstString);
} finally {
mgr.close();
}
return object;
}
1 个解决方案
#1
0
Notice that DISTINCT
only works with Indexed properties. Is any of uFullName
or uName
are not indexed, then the projection won't work.
请注意,DISTINCT仅适用于Indexed属性。 uFullName或uName中的任何一个都没有编入索引,那么投影将不起作用。
#1
0
Notice that DISTINCT
only works with Indexed properties. Is any of uFullName
or uName
are not indexed, then the projection won't work.
请注意,DISTINCT仅适用于Indexed属性。 uFullName或uName中的任何一个都没有编入索引,那么投影将不起作用。