简体   繁体   中英

Syntax error in HQL query

I have this code in my dao method:

        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());

and it throws this Exception:

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)]

Something is probably wrong with my query, but I cannot see what... Any help appreciated.

It's your parenthesis.

LOWER(a.candidate.firstName LIKE :firstName)

should be:

LOWER(a.candidate.firstName) LIKE :firstName

etc.

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