gpt4 book ai didi

Hibernate 中的 MySQL 语法错误

转载 作者:行者123 更新时间:2023-11-29 13:11:06 26 4
gpt4 key购买 nike

我使用HibernateMySQL 5.5.28数据库获取数据,这是使用org.hibernate.exception.SQLGrammarException从Hibernate查询错误:

Hibernate: 
select user0_.uid as uid1_0_0_, user0_.motorcycle as motorcyc2_0_0_, user0_.password as password3_0_0_, user0_.username as username4_0_0_
from db-jade-na-zlot.users user0_
where user0_.uid=1;

我尝试在 phpMyAdmin 中检查这一点,该查询工作正常:

select user0_.uid as uid1_0_0_, user0_.motorcycle as motorcyc2_0_0_, user0_.password as password3_0_0_, user0_.username as username4_0_0_
from users user0_
where user0_.uid=1;

我在 hibernate.cfg.xml 中检查了 5 次数据库名称,但没问题。我做错了什么?

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db-jade-na-zlot</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">vertrigo</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping class="pl.jadenazlot.model.User"></mapping>
</session-factory>

错误:

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-jade-na-zlot.users user0_ where user0_.uid=1' at line 1

最佳答案

db-jade-na-zlot 是有效的架构/数据库名称吗?
也许你需要把它加厚

``

围绕这个名称来教导 Hibernate 将其视为标识符并将其引用到生成的 SQL 中

关于Hibernate 中的 MySQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22087829/

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