I am trying to modify a standard select query in my endpoint class to fetch selected fields from my entity. However even after changing the query, I see that my query result is fetching all the fields. The code is below, you can note that the query has been updated to add my own. I am basically trying to form a query where I only fetch few properties from an entity rather than getting all(to reduce network data transaction volume). Any help is appreciated.
//QUERY MODIFIED IN THIS METHOD
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listQuizTable")
public CollectionResponse<QuizTable> listQuizTable(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<QuizTable> execute = null;
try {
mgr = getEntityManager();
//Query query = mgr.createQuery("select from QuizTable as QuizTable");
Query query = mgr.createQuery("select n.quizKey, n.quizDesc, n.uploadDate from QuizTable n");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<QuizTable>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (QuizTable obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<QuizTable> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}