我正在尝试修改端点类中的标准选择查询,以从我的实体中获取选定的字段。但是,即使在更改查询之后,我也看到我的查询结果正在获取所有字段。代码如下,您可以注意到查询已更新为添加我自己的。我基本上是在尝试形成一个查询,在该查询中我只从一个实体中获取几个属性而不是全部获取(以减少网络数据事务量)。任何帮助表示赞赏。
//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();
}