0
這是我的問題。即使我使用JDO,數據也會保存在數據存儲後端。現在我想用條件查詢檢索數據。例如,如何使用條件查詢從gae數據存儲檢索數據
public List<Query> getQueries(final EntityKind entityKind) throws RuntimeException {
System.out.println("In getQueries()!!!" + entityKind);
if (entityKind == null) {
logger.log(Level.SEVERE, "QueryService : getQueries() : entityKind is null.");
throw new RuntimeException("QueryService : getQueries() : entityKind is null.");
}
final long entityId = entityKind.getId();
PersistenceManager pm = PMF.getPersistenceManager();
List<Query> queryList = (List<Query>) new TransactionTemplate(pm).execute(new TransactionCallback<List<Query>>() {
public List<Query> doInTransaction(PersistenceManager pm) {
javax.jdo.Query query = pm.newQuery(Query.class,"SELECT FROM Query WHERE entityKindId == entityId");
Collection<Query> c = pm.detachCopyAll((Collection<Query>) query.execute(entityId));
return new ArrayList<Query>(c);
}
});
return queryList;
}
但這不起作用。我也試過這個,
public List<Query> getQueries(final EntityKind entityKind) throws RuntimeException {
System.out.println("In getQueries()!!!" + entityKind);
if (entityKind == null) {
logger.log(Level.SEVERE, "QueryService : getQueries() : entityKind is null.");
throw new RuntimeException("QueryService : getQueries() : entityKind is null.");
}
final long entityId = entityKind.getId();
PersistenceManager pm = PMF.getPersistenceManager();
List<Query> entityKindFields = (List<Query>) new TransactionTemplate(pm).execute(new TransactionCallback<List<Query>>() {
public List<Query> doInTransaction(PersistenceManager pm) {
javax.jdo.Query query = pm.newQuery(Query.class);
query.setFilter("entityKindId == :entityId");
Collection<Query> c = pm.detachCopyAll((Collection<Query>) query.execute(entityKindId));
return new ArrayList<Query>(c);
}
});
return queryList;
}
這也行不通。請幫忙!
「這不是工作」進行檢索 - 會發生什麼?什麼是「查詢」持久化類型?我建議你使用日誌來調試你的問題;因此將其設置爲DEBUG級別並專注於一位代碼。第一個查詢是錯誤的 - 看起來試圖使用顯式參數,但沒有聲明它們。基本的JDO文檔和JDO規範定義了這些東西http://datanucleus.org/products/accessplatform_3_1/jdo/jdoql.html – DataNucleus