![](/img/trans.png)
[英]Java Google appengine datastore.get throws EntityNotFoundException on an existing entity
[英]How to get an entity between two dates in appengine datastore for
我有一個約會表,其中約會日期為其中一列。 我想使用JPA檢索appengine數據存儲區中兩個日期之間的所有約會。 可以請讓我知道如何實現這一目標? 我嘗試了以下查詢,但它沒有用。
從Appointment a where(apptSts ='p'或apptSts ='a')和(apptDate> =:fromDate或apptDate <=:toDate)中選擇一個
將屬性設置為列表屬性。 然后您可以在兩個日期之間查詢。 請參閱Objectify中完成的以下測試代碼。 我想你也可以在JPA中使用相同的技術。 https://github.com/stickfigure/objectify/blob/master/src/test/java/com/googlecode/objectify/test/QueryExoticTypesTests.java
要檢索2個日期之間的約會,您需要更改查詢邏輯以包含“ 和 ”而不是“ 或 ”:
select a from Appointment
where apptDate>=fromDate and apptDate<=toDate
您可以在appengine中的同一屬性上使用不等式文件管理器,但它們不能與OR結合使用。
請參閱gql參考中的示例,該示例也應適用於JPA。
你可以應用多個不等式,但它們應該在同一個字段(變量)。我想這里出現的問題是app引擎不允許使用括號的東西,,,我的意思是
(conditionA AND conditionB .....) OR (conditionC AND conditionC .....)
//--this is not allowed.
順便說一句允許(我試過)
(conditionA AND conditionB .....) AND (conditionC AND conditionC)
//--allowed(although its bracket are meaning less here)
您只能執行大於或小於查詢的一個,因此一種方法是執行大於查詢,並遍歷結果並手動過濾掉與小於查詢不匹配的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.