Вопрос

I occured a Hibernate Query problem when I's attempting to query data by LIKE operator with parameterized value, the following is my code fragment for doing it:

String hql = "FROM Customer WHERE username LIKE :username";
Query query =sessionFactory.getCurrentSession().createQuery(hql);
query.setParameter("username", "%" + keyword + "%")

The above code runs alwasy with exception:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: LIKE near line 1

It's ok for using other query operators like =, !=, > with parameterized values, and just get confused to this and how can I use Hibernate query's like operator with parameterized values?

Thanks in advance!

Это было полезно?

Решение

String hql = "FROM Customer WHERE username LIKE ':username'";
Query query =sessionFactory.getCurrentSession().createQuery(hql);
query.setParameter("username", "%" + keyword + "%")
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top