java - MismatchedTokenException : expecting "set", 发现 '='

标签 java spring postgresql hibernate

在我的 java spring boot 应用程序中,我正在使用 postgresql。我正在尝试运行以下查询

String update = "update User" +
            "set temporaryRandomToken = :randomToken" +
            "where id = :userId";
     org.hibernate.query.Query<?> sql = createHql(update)
             .setParameter("randomToken", "12aswqq")
             .setParameter("userId", 1);

问题是,当我运行查询时它会提示

MismatchedTokenException: expecting "set", found '='

userIdrandomToken 必须动态更改,所以不要向我提供静态查询字符串。

最佳答案

你需要在两行的开头有一个空格(在“set”和“where”之前):

String update = "update User" +
        " set temporaryRandomToken = :randomToken" +
        " where id = :userId";

关于java - MismatchedTokenException : expecting "set", 发现 '=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47153189/

相关文章:

Java 无法解析的日期格式差异

spring - RedirectAttributes 在 Spring 3.1 中给出 IllegalStateException

postgresql如何让COPY自动解释格式化的数字字段?

java - 插入 postgres 数据库 - 印地语

java - hadoop程序中的类型不匹配错误

java - Spring Security Active Directory 忽略 PartialResultException

java - 如何在 Java 中格式化字符串

css - 带 CSS 的 Apache Tiles 2.1.4

spring - 配置问题:Spring NamespaceHandler for [http://www. springframework.org/schema/mvc]

PostgreSQL:无法连接到服务器:端口 5432 上的 TCP/IP 连接