首页 文章

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

提问于
浏览
1

嗨伙计们,我正在尝试使用HQL编辑器从我的数据库中检索数据进行查询 . 我按照示例“在Java Swing应用程序中使用Hibernate”中的步骤进行操作 . 我的配置文件如下:

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

制图:

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

使用此: from nationalfrom National 我收到以下错误:

org.hibernate.exception.SQLGrammarException:无法在org上的org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)的org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)执行查询 . 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)的org.hibernate.loader.Loader.list(Loader.java:2099)上的hibernate.loader.Loader.doList(Loader.java:2223)位于org.hibernate.impl.SessionImpl.list(SessionImpl.java)的org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)中的.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912) :1121)org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:)中的sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)第1行的'from limit 100'附近使用正确的语法 . 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) )com.mysql.jdbc.Util.getInstance(Util.java:386)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) :2163)com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)at com.mysql.jdbc.PreparedStatement.executeInternal(Prepa) redStatement.java:2127)com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)atg.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)atg.hibernate.loader.Loader.getResultSet (Loader.java:1787)org.hibernate.loader.Ladader.doQuery中的org.hibernate.loader.doQuery.doQuery.doQueryAndInitializeNonLazyCollections(Loader.java:236)中的org.hibernate.loader.Loader.doQuery(Loader.java:674) . doList(Loader.java:2220)......还有8个

1 回答

  • 0

    使用

    from mobilecarriers.entity.National
    

相关问题