gpt4 book ai didi

java - HQL 查询中的语法错误

转载 作者:行者123 更新时间:2023-12-01 22:45:53 25 4
gpt4 key购买 nike

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

我的查询可能有问题,但我看不到什么......任何帮助表示赞赏。

最佳答案

这是你的括号。

LOWER(a.candidate.firstName LIKE :firstName)

应该是:

LOWER(a.candidate.firstName) LIKE :firstName

等等

关于java - HQL 查询中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25380622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com