简体   繁体   中英

How to get an entity between two dates in appengine datastore for

I have an appointment table with appointment date as one of the columns. I want to retrieve all the appointments between two dates in appengine datastore using JPA. can please let me know how to achieve this? I tried with following query but it did not work.

select a from Appointment a where (apptSts='p' or apptSts='a') and (apptDate>=:fromDate or apptDate<=:toDate)

Make the property as a list property. Then you can query between two dates. See the following test code done in Objectify. I think you can use the same technique in JPA also. https://github.com/stickfigure/objectify/blob/master/src/test/java/com/googlecode/objectify/test/QueryExoticTypesTests.java

To retrieve appointments between 2 dates, you need to change your query logic to include " and " instead of " or " :

select a from Appointment
where apptDate>=fromDate and apptDate<=toDate

You CAN have inequality filers on the same property in appengine, but they can't be combined with OR.

See examples in gql reference , which should also apply to JPA.

You can apply multiple inequality but they should be on the same field (variable).I guess whats going wrong here is that app engine doesn't allow to use the bracket things ,,,i mean

(conditionA AND conditionB .....) OR (conditionC AND conditionC .....)
//--this is not allowed.

By the way following is allowed(i tried it)

(conditionA AND conditionB .....) AND (conditionC AND conditionC)
//--allowed(although its bracket are meaning less here)

您只能执行大于或小于查询的一个,因此一种方法是执行大于查询,并遍历结果并手动过滤掉与小于查询不匹配的结果。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM