开发者

Google App Engine, JDO, use Date in filter

In my application, I would like to fetch a set of entities from the Datastore, that have a Date field set to a date before the present moment.

I do realize, that one 开发者_运维技巧of the ways of doing that is by simply storing the date in those entities as just a long value in milliseconds.

But ist there actually a way of storing them as Dates and being able to use them for filtering?

I tried something like query.setFilter("dateField.before(dateParam)"); , but it didnt work, neither did the simple comparison.

Thanks in advance.


Simply declare the dateField as java.util.Date, then use

query.setFilter("dateField < dateParam");
query.declareParameters("java.util.Date dateParam");
List<...> results = (List<...>) query.execute(new java.util.Date());

See examples here: http://code.google.com/appengine/docs/java/datastore/queriesandindexes.html


Constantin's solutions gives:

Operator < cannot be used as part of the join condition.

Adding a colon before parameter name made it work for me:

q.setFilter("createdTime < :nowTime");
List<...> result = (List<...>) q.execute(new java.util.Date());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜