strut2 を Hibernate に統合するのにひどく行き詰まっています。
私はネットビーンズ7.1.2を使用しています
Derby (Java DB) データベースのテーブル「QUESTION」のすべての行を表示する非常に単純な Java EE プロジェクトがあります。テーブルを作成し、hibernate.cfg.xml ファイルにマップしました。
しかし、右クリックして「HQLクエリの実行」に移動し、クエリを実行すると
「質問から」、次のエラーが表示されます。
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.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
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: java.sql.SQLSyntaxErrorException: Table/View 'RAMBO.QUESTION' does not exist.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 9 more
Caused by: org.apache.derby.client.am.SqlException: Table/View 'RAMBO.QUESTION' does not exist.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
... 17 more
私の 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.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/Q4U</property>
<property name="hibernate.connection.username">rambo</property>
<property name="hibernate.connection.password">ho</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="hibernate.hbm.xml"/>
<mapping/>
</session-factory>
</hibernate-configuration>
私の Hibernate.hbm.xml ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="beans.Question" table="RAMBO.QUESTION">
<id name="qid" type="java.lang.Integer">
<column name="QID" />
<generator class="increment" />
</id>
<property name="opc" type="java.lang.Integer">
<column name="OPC" not-null="true"/>
</property>
<property name="uid" type="java.lang.Integer">
<column name="UID" not-null="true"/>
</property>
<property name="cid" type="java.lang.Integer">
<column name="CID" not-null="true"/>
</property>
<property name="abuse" type="java.lang.Integer">
<column name="ABUSE" not-null="true"/>
</property>
<property name="accuracy" type="java.lang.Float">
<column name="ACCURACY" not-null="true"/>
</property>
<property name="poston" type="java.util.Date">
<column name="POSTON" not-null="true"/>
</property>
<property name="body" type="java.lang.String">
<column name="BODY" not-null="true"/>
</property>
<property name="op1" type="java.lang.String">
<column name="OP1" not-null="true"/>
</property>
<property name="op2" type="java.lang.String">
<column name="OP2" not-null="true"/>
</property>
<property name="op3" type="java.lang.String">
<column name="OP3" not-null="true"/>
</property>
<property name="op4" type="java.lang.String">
<column name="OP4" not-null="true"/>
</property>
<property name="op5" type="java.lang.String">
<column name="OP5" not-null="true"/>
</property>
<property name="cname" type="java.lang.String">
<column name="CNAME" not-null="true"/>
</property>
</class>
</hibernate-mapping>
Hibernate.reveng.xml ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-schema="RAMBO"/>
<table-filter match-name="USERS"/>
<table-filter match-name="CATEGORY"/>
<table-filter match-name="TESTS"/>
<table-filter match-name="INBOX"/>
<table-filter match-name="QUESTION"/>
<table-filter match-name="ADMIN"/>
</hibernate-reverse-engineering>
Question.java
package beans;
import java.io.Serializable;
import java.util.Date;
public class Question implements Serializable {
int qid, opc, uid, cid, abuse;
float accuracy;
Date poston;
String body, op1, op2, op3, op4, op5, cname;
// Also public getters and setters
}
FindQuestion.java
package controller;
import beans.Question;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
public class FindQuestion extends ActionSupport {
private List questionList = new ArrayList();
@Override
public String execute() throws Exception {
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
this.questionList = (List<Question>) session.createQuery("from Question");
session.getTransaction().commit();
} catch (Exception e) {
}
return SUCCESS;
}
}