【问题标题】:Hibernate HQL unexpected token with Likes带有喜欢的 Hibernate HQL 意外令牌
【发布时间】:2017-05-02 04:26:22
【问题描述】:

我的 Spring Web 模型-视图-控制器 (MVC) 框架中有这个类。 Spring Web 模型-视图-控制器 (MVC) 框架的版本是 3.2.8。

我在 1 个 DAO 中有这个方法

final StringBuilder queryString = new StringBuilder("  select app from Application app where upper (ticket_id) like :searchString and upper (id) like :searchString " );

        queryString.append("where  app.status != " + Status.READY.ordinal());

        queryString.append(" order by app.submissionTime desc ");

        try {

            final Query query = getEntityManager().createQuery(queryString.toString());

            searchString = searchString.replace("!", "!!")
                       .replace("%", "!%")
                       .replace("_", "!_")
                       .replace("[", "![")
                       .trim()
                       .toUpperCase();


            query.setParameter ("searchString", searchString);                      

            return query.getResultList();

但我在运行时出现此错误:

 org.   where near line 1, column 144 [  select app from com.tdk.devices.domain.Application app where upper (ticket_id) like :searchString and upper (id) like :searchString where  app.status != 0 order by app.submissionTime desc ]

【问题讨论】:

  • 第 144 列是 app.status 的开始 - 与喜欢无关

标签: java sql spring hibernate spring-mvc


【解决方案1】:

您使用了 2 次“where”子句。先在StringBuilder的构造函数中,然后:

queryString.append("where  app.status != " + Status.READY.ordinal());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-13
    • 2015-05-21
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多