2011-01-09 57 views
1

我試圖通過Google App Engine數據存儲區中的鍵來查詢實體的集合。這是我嘗試沒有成功執行查詢:GAE/J數據存儲區:如何使用JDO構建IN查詢

Query query = pm.newQuery(Fix.class); 
query.setFilter("__key__ IN param"); 
query.declareParameters("com.google.appengine.api.datastore.Key param"); 
query.execute(list); // list is an array of keys 

而我得到的錯誤是:

javax.jdo.JDOUserException: Portion of expression could not be parsed: IN param 

是否有可能使用建立與JDO或低級API IN詢問通過鍵找到實體?

回答

0

您是否嘗試過this page的示例?例如:

query.addFilter("__key__", Query.FilterOperator.IN, param); 

請注意,param應該是一個列表。

3

我想你可能會混淆了JDO和JPA語法:請參閱第this範例

JPA:

select from Person where 
    favoriteFood IN ('cheeseburger', 'pizza', 'fried chicken') 
    order by favoriteFood, age 

JDO:

Query q = pm.newQuery(
    "select from Person where :p1.contains(favoriteFood) order by favoriteFood, age"); 
q.execute(Arrays.asList("cheeseburger", "pizza", "fried chicken")); 
相關問題