HQL查询中的语法错误

时间:2014-08-19 10:02:07

标签: java hibernate hql

我的dao方法中有这个代码:

        TypedQuery<Application> query = em.createQuery(
            "FROM Application a "
            + "WHERE LOWER(a.candidate.firstName LIKE :firstName) "
            + "OR LOWER(a.candidate.lastName LIKE :lastName) "
            + "OR (a.candidate.phoneNumber LIKE :phoneNumber) "
            + "OR LOWER(a.candidate.email LIKE :email) "
            + "OR LOWER(a.candidate.postcode LIKE :postcode)"
        , Application.class);
    query = query.setParameter("firstName", candidate.getFirstName());
    query = query.setParameter("lastName", candidate.getLastName());
    query = query.setParameter("phoneNumber", candidate.getPhoneNumber());
    query = query.setParameter("email", candidate.getEmail());
    query = query.setParameter("postcode", candidate.getPostcode());

并抛出此异常:

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: ( near line 1, column 57 [FROM com.xxx.xxx.entity.Application a WHERE LOWER(a.candidate.firstName LIKE :firstName) OR LOWER(a.candidate.lastName LIKE :lastName) OR (a.candidate.phoneNumber LIKE :phoneNumber) OR LOWER(a.candidate.email LIKE :email) OR LOWER(a.candidate.postcode LIKE :postcode)]

我的查询可能有些问题,但我看不清楚......有任何帮助表示感谢。

1 个答案:

答案 0 :(得分:3)

这是你的括号。

LOWER(a.candidate.firstName LIKE :firstName)

应该是:

LOWER(a.candidate.firstName) LIKE :firstName