开发者

How to do a Date range query using JDO on Google App Engine

开发者 https://www.devze.com 2023-02-09 10:15 出处:网络
Here is the code snippet I am trying to get to work: final Query query = pm.newQuery(\"SELECT FROM model.Strip WHERE publishOn <= startDate

Here is the code snippet I am trying to get to work:

final Query query = pm.newQuery("SELECT FROM model.Strip WHERE publishOn <= startDate
&& endDate >= publishOn PARAMETERS Date startDate, Date endDate import java.util.Date");

Since I am only querying on a single parameter, this should work according to the Google Docs.

Inequality Filters Are Allowed on One Property Only A query may only use inequality filters (<, <=, >=, >, !=) on one property across all of its filters. For example, this query is allowed:

import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.SortDirection;

Query q = new Query("Person");
q.addFilter("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYearParam);
q.addFilter("birthYear", FilterOperator.LESS_THAN_OR_EQUAL, maxBirthYearParam);

of course that is using the low-level Datastore interface, but I would expect that the JDO implementation just uses that as well.

But I am getting 开发者_StackOverflowthis un-helpful error message when I run my query.

org.datanucleus.store.appengine.query.DatastoreQuery$UnsupportedDatastoreFeatureException: Problem with query = publishOn PARAMETERS Date startDate, Date endDate import java.util.Date>: Unexpected expression type while parsing query: org.datanucleus.query.expression.ParameterExpression

Does anyone know how to do a ranged query like this


I figured it out . . .

final Query query = pm.newQuery("SELECT FROM model.Strip WHERE publishOn <= startDate
&& endDate >= publishOn PARAMETERS Date startDate, Date endDate import java.util.Date");

changed to

final Query query = pm.newQuery("SELECT FROM model.Strip WHERE this.publishOn >= startDate
&& this.publishOn <= endDate PARAMETERS java.util.Date startDate, java.util.Date endDate");

you have to put the property before the variable, the this. doesn't hurt either

I switched to Objectify so I would have to fight these stupid JDO/JPAsemantics!

0

精彩评论

暂无评论...
验证码 换一张
取 消