【发布时间】:2013-05-09 15:19:28
【问题描述】:
我是 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();
}
这行不通。
错误
原因:异常 [EclipseLink-8025] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JPQLException 异常描述:语法错误解析查询 [SELECT a FROM Attendant a WHERE a.staffNo = :staffNo AND a.nodeCode = :nodeCode AND DATE(a.attendantDate) = :attendantDate],第 1 行,第 88 列:意外令牌 [( ]。 内部异常:NoViableAltException(83@[()* loopback of 383:9: (d= DOT right= attribute )*])
【问题讨论】:
标签: jpa