简体   繁体   中英

JPQL work with LIKE statement and AND condition

may I ask my JPQL statement consist any error? Or the AND condition cannot work with LIKE statement?

public List searchByTime(String from, String to, String a){
 Query q = em.createQuery("SELECT e FROM EnrollmentDetails e WHERE (e.startTime >= ?1 AND e.endTime <= ?2) AND (e.offerCode.offerCode LIKE: ?3)");
 q.setParameter(1,  from);
 q.setParameter(2,  to);
 q.setParameter(3,   a + "%");
  List l = q.getResultList();
  return l;
} 

Whenever I remove AND (e.offerCode.offerCode LIKE: ?3) and q.setParameter(3, a + "%"); , then the statement is work, but without the result what I want.

I'm pretty sure the 2 statements that I removed are correct as they work in other function.

Just in this function is not working. Can anyone help me.

thank you.

You have a colon : just after the LIKE keyword which is illegal. A : can only be used as part of a named parameter. Remove that and it likely will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM