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.
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;
}
DISTINCT
with single column then it returns distinct data but if i use it with multiple columns then it returns duplicates. – ZankhnauserName = abc
.If i use onlyDistint uFullName where uName = 'abc'
then it returns single record with value and if i useDistinct uFullName,uUrl where uName = 'abc'
then it returns all 12 record without any effect of distinct query. – Zankhna