こんにちは、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 national
またはfrom National
、次のエラーが表示されます:
org.hibernate.exception.SQLGrammarException: org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) でクエリを実行できませんでした org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) で org.hibernate .loader.Loader.doList(Loader.java:2223) org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) org.hibernate.loader.Loader.list(Loader.java:2099) org. 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 構文にエラーがあります。Sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) の sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java: 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.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) com.mysql.jdbc.PreparedStatement .executeInternal(PreparedStatement.java:2127) com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293) org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) org.hibernate.loader. Loader.getResultSet(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 つ以上2624) com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127) で com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293) で org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java) :186) org.hibernate.loader.Loader.getResultSet(Loader.java:1787) で org.hibernate.loader.Loader.doQuery(Loader.java:674) で org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader. java:236) at org.hibernate.loader.Loader.doList(Loader.java:2220) ... 8 もっと見る2624) com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127) で com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293) で org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java) :186) org.hibernate.loader.Loader.getResultSet(Loader.java:1787) で org.hibernate.loader.Loader.doQuery(Loader.java:674) で org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader. java:236) at org.hibernate.loader.Loader.doList(Loader.java:2220) ... 8 もっと見るorg.hibernate.loader.Loader.doQuery(Loader.java:674) で getResultSet(Loader.java:1787) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) で org.hibernate.loader.Loader .doList(Loader.java:2220) ... 8 つ以上org.hibernate.loader.Loader.doQuery(Loader.java:674) で getResultSet(Loader.java:1787) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) で org.hibernate.loader.Loader .doList(Loader.java:2220) ... 8 つ以上