2011-04-06 49 views
0

我試圖從Java web服務訪問MySQL數據庫。我使用NetBeans IDE和我下面的教程Using Hibernate in a Web ApplicationNetBeans HQL編輯器錯誤地轉換爲SQL

現在,當我嘗試測試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

我輸入的HQL查詢

from call 

,而應該是:

from Call 

以大寫首字母。

愚蠢的錯誤,我認爲這是數據庫表,但顯然它是POJO名稱,你必須指定。