Datetime to Date (MySQL) in JPA createQuery error Exception [EclipseLink-8025] -
i'am new in java , jpa. use command
select * asm.attendant staff_no='0004' , node_code='kt1' , date(attendant_date) = '2013-05-13';
in mysql it's work
but
when use in 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 attendant a.staffno = :staffno , a.nodecode = :nodecode , date(a.attendantdate) = :attendantdate", attendant.class); result.setparameter("staffno", staffno); result.setparameter("nodecode", nodecode); result.setparameter("attendantdate", attendantdate); return result.getresultlist(); }
it's not work.
error
caused by: exception [eclipselink-8025] (eclipse persistence services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.jpqlexception exception description: syntax error parsing query [select attendant a.staffno = :staffno , a.nodecode = :nodecode , date(a.attendantdate) = :attendantdate], line 1, column 88: unexpected token [(]. internal exception: noviablealtexception(83@[()* loopback of 383:9: (d= dot right= attribute )*])
date() not valid jpql. in jpa createquery() takes jpql not sql. if want sql use createnativequery().
or, in jpql mark date parameter :date set parameter instance of java.sql.date.
Comments
Post a Comment