JPA createQuery中的Datetime-to-Date(MySQL)错误异常[EclipseLink-8025]

JPA createQuery中的Datetime-to-Date(MySQL)错误异常[EclipseLink-8025],jpa,Jpa,我是JAVA和JPA新手。 我使用命令 select * from asm.attendant where staff_no='0004' and node_code='KT1' and date(attendant_date) = '2013-05-13'; 在MySQL中,这是工作 但是 当我在JPA中使用 public List<Attendant> listAttendantByStaffNoAndNodeCodeAndDateWs(String staffNo,S

我是JAVA和JPA新手。 我使用命令

select * from asm.attendant where staff_no='0004' and node_code='KT1' and date(attendant_date) = '2013-05-13';
在MySQL中,这是工作

但是

当我在JPA中使用

    public List<Attendant> listAttendantByStaffNoAndNodeCodeAndDateWs(String staffNo,String nodeCode,String attendantDateData) throws ParseException {

    Date attendantDate = new SimpleDateFormat("yyyy-MM-dd").parse(attendantDateData);

    Query result =  em.createQuery("SELECT a FROM Attendant a WHERE a.staffNo = :staffNo AND a.nodeCode = :nodeCode AND DATE(a.attendantDate) = :attendantDate", Attendant.class);
    result.setParameter("staffNo", staffNo);
    result.setParameter("nodeCode", nodeCode);
    result.setParameter("attendantDate", attendantDate);
    return result.getResultList();
}  
公共列表listAttendantByStaffNoAndNodeCodeAndDateWs(字符串staffNo、字符串nodeCode、字符串attendantDateData)引发ParseException异常{
日期attendantDate=新的SimpleDateFormat(“yyyy-MM-dd”)。解析(attendantDateData);
查询结果=em.createQuery(“从助理a中选择一个,其中a.staffNo=:staffNo和a.nodeCode=:nodeCode和DATE(a.attendantDate)=:attendantDate”,Attendant.class);
result.setParameter(“staffNo”,staffNo);
result.setParameter(“nodeCode”,nodeCode);
result.setParameter(“attendantDate”,attendantDate);
返回result.getResultList();
}  
这不是工作

错误

引起原因:异常[EclipseLink-8025](Eclipse持久性服务-2.3.2.v20111125-r10461):org.Eclipse.Persistence.exceptions.JPQLException 异常描述:语法错误分析查询[从助理a中选择a,其中a.staffNo=:staffNo和a.nodeCode=:nodeCode和DATE(a.attendantDate)=:attendantDate],第1行第88列:意外标记[(]。 内部异常:NoViableAltException(83@[()*383:9的环回:(d=DOT right=attribute)*])

日期()不是有效的JPQL。在JPA中,createQuery()接受JPQL而不是SQL。如果需要SQL,请使用createNativeQuery()

或者,在JPQL中,只需将日期标记为参数:date any将参数设置为java.sql.date的实例