Question

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)

Was it helpful?

Solution

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.

OTHER TIPS

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

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)

You can only do one greater than or less than query, so one way to do it is to do a greater than query, and walk through the results and manually filter out the ones that don't match the less than query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top