Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 从JPQL中的时间戳变量提取年/月_Jpa_Eclipselink - Fatal编程技术网

Jpa 从JPQL中的时间戳变量提取年/月

Jpa 从JPQL中的时间戳变量提取年/月,jpa,eclipselink,Jpa,Eclipselink,在JSF+JPA应用程序中,需要按年份和月份搜索名为“createdAt”的时间戳属性。我使用了Extract(Year,createdAt),但它给出了一个错误 持久性提供程序是EclipseLink 2.6(这是Netbeans中当前的默认值)。数据库是MySQL 这是一个简化的查询 select c from Client c where EXTRACT(YEAR,c.createdAt)=:ey and EXTRACT(MONTH,c.createdAt)=:eq 错误是 Exce

在JSF+JPA应用程序中,需要按年份和月份搜索名为“createdAt”的时间戳属性。我使用了Extract(Year,createdAt),但它给出了一个错误

持久性提供程序是EclipseLink 2.6(这是Netbeans中当前的默认值)。数据库是MySQL

这是一个简化的查询

select c from Client c where EXTRACT(YEAR,c.createdAt)=:ey and  EXTRACT(MONTH,c.createdAt)=:eq 
错误是

Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [select count(distinct c)    from ClientEncounterComponentItem i join i.itemClient c  where i.retired=:f  and i.item=:v1  and i.integerNumberValue>:d1 and EXTRACT(YEAR,c.createdAt)=:ey and  EXTRACT(MONTH,c.createdAt)=:eq  and i.itemClient.person.province=:area    ]. 
[154, 166] The right expression is not a valid expression.
[167, 263] The query contains a malformed ending.
显示查询正确格式的文档应为:

select c from Client c where EXTRACT(YEAR FROM c.createdAt)=:ey and  EXTRACT(MONTH FROM c.createdAt)=:eq

EclipseLink单元测试验证了在支持该格式的数据库上使用Hermes解析器时该格式的有效性。

简化您的查询-是Extract或其他子句的问题吗?简化了查询为什么不使用“select c from Client c where Extract(YEAR,c.createdAt)=:ey”并显示新的异常消息和堆栈跟踪?根据()您还可以尝试“EXTRACT(YEAR FROM c.createdAt)=:ey”什么是Hermes解析器?MySQL支持吗?Hermes是EclipseLink用于JPQL处理的解析器,帮助它生成表达式,然后生成SQL。