我试图从Java web服务访问MySQL数据库。我正在使用NetBeans IDE,并遵循教程在Web应用程序中使用Hibernate
现在当我尝试测试HQL查询:从调用我得到:
org.hibernate.exception.SQLGrammarException: could not execute query
blablabla
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'from limit 100' at line 1
bla, bla, bla
和翻译的SQL也是错误的:
select from
我使用Hibernate逆向工程创建了call .java类。
Hibernate.cfg.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/datacheck</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">####</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
</session-factory>
</hibernate-configuration>
我似乎找不到错误,我搜索了整个互联网:p
类似的线程是HQL编辑器没有在查询中附加表名。
我输入了HQL查询
from call
而它应该是:
from Call
首字母大写
愚蠢的错误,我认为这是数据库表,但显然这是POJO名称,你必须指定