简体   繁体   English

使用HQL编辑器进行查询时出现休眠错误

[英]Hibernate error when using HQL Editor to query

Hi guys I'm trying to retrieve data from my database using the HQL Editor to query. 嗨,大家好,我正在尝试使用HQL编辑器从数据库中检索数据进行查询。 I followed the steps in the example "Using Hibernate in a Java Swing Application". 我按照示例“在Java Swing应用程序中使用休眠”中的步骤进行操作。 My config files is as follow: 我的配置文件如下:

<?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/mobilecarriers?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">######</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    <property name="hibernate.c3p0.min_size">1</property>
    <property name="hibernate.c3p0.max_size">100</property>
    <property name="hibernate.c3p0.timeout">0</property>
    <property name="hibernate.c3p0.max_statements">0</property>
    <property name="hibernate.c3p0.idle_test_period">0</property>
    <mapping resource="mobilecarriers/entity/National.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

mapping: 映射:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 23 Sep 2012 11:26:47 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="mobilecarriers.entity.National" table="national" catalog="mobilecarriers">
        <id name="id" type="java.lang.Short">
            <column name="id" />
            <generator class="identity" />
        </id>
        <property name="dominantSecondLanguage" type="string">
            <column name="DominantSecondLanguage" length="25" />
        </property>
    </class>
</hibernate-mapping>

Using this: from national or from National i get the following errors: 使用此方法: from nationalfrom National获得以下错误:

org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2223) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) at org.hibernate.loader.Loader.list(Loader.java:2099) at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; org.hibernate.exception.SQLGrammarException:无法在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)的org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)处执行查询org.hibernate.loader.Loader.list的.loader.Loader.doList(Loader.java:2223)org org.hibernate.loader.Loader.list(Loader.java:2099)的IgnoreQueryCache(Loader.java:2104)。位于org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)的hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912)位于org.hibernate.impl.SessionImpl.list(SessionImpl.java: 1121),位于org.hibernate.impl.QueryImpl.list(QueryImpl.java:79),原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from limit 100' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) at com.mysql.jdbc.PreparedStatement.executeInternal(Prepa 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java)的sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)附近使用: 57),位于com.mysql.jdbc.Util.handleNewInstance(Util.java:411)上java.lang.reflect.Constructor.newInstance(Constructor.java:525)处的sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) )的com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)的com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)的com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java: 3609)在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)在com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)处的com.mysql.jdbc.PreparedStatement.executeInternal(Prepa:2163) redStatement.java:2127) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) at org.hibernate.loader.Loader.doQuery(Loader.java:674) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) at org.hibernate.loader.Loader.doList(Loader.java:2220) ... 8 more com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)的org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)的org.hibernate.loader.Loader.getResultSet的redStatement.java:2127) (Loader.java:1787)在org.hibernate.loader.Loader.doQuery(Loader.java:674)在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)在org.hibernate.loader.Loader。 doList(Loader.java:2220)...还有8个

采用

from mobilecarriers.entity.National

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM