这是我的问题。我正在使用JDO,数据保存在数据存储区后端。现在我想用带条件的查询检索数据。例如,
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;
}
这也行不通。请帮忙!