使用HQL编辑器查询时发生Hibernate错误 [英] Hibernate error when using HQL Editor to query
问题描述
我试图从数据库中使用HQL编辑器来查询数据。我遵循示例在Java Swing应用程序中使用Hibernate中的步骤。我的配置文件如下:
<?xml version =1.0encoding =UTF-8?>
<!DOCTYPE hibernate-configuration PUBLIC - // Hibernate / Hibernate Configuration DTD 3.0 // ENhttp://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>根< / 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映射DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\"> ;
<! - 生成23 Sep 2012 11:26:47 PM by Hibernate Tools 3.2.1.GA - >
< hibernate-mapping>
< class name =mobilecarriers.entity.Nationaltable =nationalcatalog =mobilecarriers>
< id name =idtype =java.lang.Short>
< column name =id/>
< generator class =identity/>
< / id>
< property name =dominantSecondLanguagetype =string>
< column name =DominantSecondLanguagelength =25/>
< / property>
< / class>
< / hibernate-mapping>
使用这个:来自国家
或 from National
我得到以下错误:
org.hibernate.exception.SQLGrammarException:可能不在
执行查询
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java :43)
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。列表(QueryImpl.java:79)引起:
com.mysql.jdbc .exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有
错误;检查与您的
MySQL服务器版本相对应的手册,以便在
的第1行附近使用正确的语法来使用'$ limit'100''。sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance 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)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)at
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)at
com.mysql .jdbc.MysqlIO.sqlQueryDirect(我
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)at
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
at
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at $ b $ org.hibernate.loader.Loader.getResultSet(Loader.java:1787)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
$从mobilecarriers.entity使用
解决方案全国
Hi guys I'm trying to retrieve data from my database using the HQL Editor to query. I followed the steps in the example "Using Hibernate in a Java Swing Application". 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:
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; 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(PreparedStatement.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
解决方案 Use
from mobilecarriers.entity.National
这篇关于使用HQL编辑器查询时发生Hibernate错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文