NetBeans HQL editor wrong translation to SQL

£可爱£侵袭症+ 提交于 2019-12-11 17:33:01

问题


I'm trying to access a MySQL database from a Java webservice. I'm using the NetBeans IDE and am following the tutorial Using Hibernate in a Web Application

Now when I try to test the HQL query: from calls I get:

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

And the translated SQL is also wrong:

select  from

I created the calls.java class using Hibernate Reverse Engineering.

This is the Hibernate.cfg.xml file:

<?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>

I can't seem to find the error, and I searched the whole Internet :p

A similar thread is HQL Editor not appending table name in query.


回答1:


I typed the HQL query

from call

while it should be:

from Call

with a capital first letter.

Dumb mistake, I thought it was the database table, but apparently it's the POJO name that you have to specify.



来源:https://stackoverflow.com/questions/5570213/netbeans-hql-editor-wrong-translation-to-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!