How to get entity between two dates in appengine datastore for
I have an appointment table with appointment date as one of the columns. I want to get all appointments between two dates in the appengine store using JPA. please let me know how to achieve this? I tried the following request but it didn't work.
select a from Destination a where (apptSts = 'p' or apptSts = 'a') and (apptDate> =: fromDate or apptDate <=: toDate)
source to share
To get appointments between two 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 files on the same property in the appengine, but they cannot be combined with OR.
See examples in the gql link , which should also apply to JPA.
source to share
Make property as list property. Then you can request between two dates. See the following test code done at Objectify. I think you can use the same technique in JPA as well. https://github.com/stickfigure/objectify/blob/master/src/test/java/com/googlecode/objectify/test/QueryExoticTypesTests.java
source to share
You can apply multiple inequality, but they must be in the same field (variable). I think what is going wrong is that the application engine does not allow for parenthesis elements, I mean
(conditionA AND conditionB .....) OR (conditionC AND conditionC .....)
//--this is not allowed.
By the way, the following is acceptable (I tried)
(conditionA AND conditionB .....) AND (conditionC AND conditionC)
//--allowed(although its bracket are meaning less here)
source to share