NetBeans HQL编辑器错误地转换为SQL

时间:2011-04-06 17:04:31

标签: sql hibernate netbeans hql reverse-engineering

我正在尝试从Java Web服务访问MySQL数据库。我正在使用NetBeans IDE,并且遵循教程 Using Hibernate in a Web Application

现在,当我尝试测试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 Reverse Engineering创建了calls.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 Editor not appending table name in query

1 个答案:

答案 0 :(得分:1)

我输入了HQL查询

from call

虽然它应该是:

from Call

首写字母。

愚蠢的错误,我认为这是数据库表,但显然它是你必须指定的POJO名称。