gpt4 book ai didi

java - 无法在 Java 中使用 HQL 运行更新查询

转载 作者:行者123 更新时间:2023-12-01 10:21:53 26 4
gpt4 key购买 nike

我正在尝试使用 HQL 运行更新查询。我觉得我在查询中遗漏了一些东西。因为插入查询工作正常。我的 HQL 查询是

Query query = session.createQuery("update school set dbvalue = :dbvalue" +
" where nameValue= :nameValue and uid = :uid");
query.setParameter("dbvalue", dashBoardValue);
query.setParameter("nameValue ", nameValue );
query.setParameter("uid", userId);

int rowsAffected = query.executeUpdate();

我收到的错误是

org.hibernate.hql.internal.ast.QuerySyntaxException: school is not mapped [update school set dbvalue = :dbvalue where nameValue = :nameValue and uid = :uid]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)

我的 hibernate.cfg.xml 是

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/intu</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.cni.school" />
</session-factory>
</hibernate-configuration>

还有什么需要补充的吗?

最佳答案

我见过 JPQL,或者也许是 HQL,坚持让实体的大小写与语句中的大小写相匹配。尝试学校

编辑:这是 Hibernate 文档在 Case Sensitivity 上所说的内容(至少版本 4.3) .

关于java - 无法在 Java 中使用 HQL 运行更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546162/

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