我们需要确保 JPQL 查询只返回最近 30 天内的结果。一个例子如下:
Date now = new Date();
Timestamp thirtyDaysAgo = new Timestamp(now.getTime() - 86400000*30);
Query query = em.createQuery(
"SELECT msg FROM Message msg "+
"WHERE msg.targetTime < CURRENT_TIMESTAMP AND msg.targetTime > {ts, '"+thirtyDaysAgo+"'}");
List result = query.getResultList();
这是我们收到的错误:
<openjpa-1.2.3-SNAPSHOT-r422266:907835 非致命用户错误> org.apache.openjpa.persistence.ArgumentException:解析查询过滤器时发生错误 'SELECT msg FROM BroadcastMessage msg WHERE msg.targetTime < CURRENT_TIMESTAMP AND msg.targetTime > {ts,'2010-04-18 04:15:37.827'}'。错误消息:org.apache.openjpa.kernel.jpql.TokenMgrError:第 1 行第 217 列的词法错误。遇到:“{”(123),之后:“”
帮助!