MySQL来自Hibernate语法错误

时间:2014-02-28 06:27:04

标签: mysql hibernate

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

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

1 个答案:

答案 0 :(得分:1)

db-jade-na-zlot有效的架构/数据库名称吗? 可能你需要加厚

  

``

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