![](/img/trans.png)
[英]Java Google appengine datastore.get throws EntityNotFoundException on an existing entity
[英]How to get an entity between two dates in appengine datastore for
我有一个约会表,其中约会日期为其中一列。 我想使用JPA检索appengine数据存储区中两个日期之间的所有约会。 可以请让我知道如何实现这一目标? 我尝试了以下查询,但它没有用。
从Appointment a where(apptSts ='p'或apptSts ='a')和(apptDate> =:fromDate或apptDate <=:toDate)中选择一个
将属性设置为列表属性。 然后您可以在两个日期之间查询。 请参阅Objectify中完成的以下测试代码。 我想你也可以在JPA中使用相同的技术。 https://github.com/stickfigure/objectify/blob/master/src/test/java/com/googlecode/objectify/test/QueryExoticTypesTests.java
要检索2个日期之间的约会,您需要更改查询逻辑以包含“ 和 ”而不是“ 或 ”:
select a from Appointment
where apptDate>=fromDate and apptDate<=toDate
您可以在appengine中的同一属性上使用不等式文件管理器,但它们不能与OR结合使用。
请参阅gql参考中的示例,该示例也应适用于JPA。
你可以应用多个不等式,但它们应该在同一个字段(变量)。我想这里出现的问题是app引擎不允许使用括号的东西,,,我的意思是
(conditionA AND conditionB .....) OR (conditionC AND conditionC .....)
//--this is not allowed.
顺便说一句允许(我试过)
(conditionA AND conditionB .....) AND (conditionC AND conditionC)
//--allowed(although its bracket are meaning less here)
您只能执行大于或小于查询的一个,因此一种方法是执行大于查询,并遍历结果并手动过滤掉与小于查询不匹配的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.