単体テストを実行しようとすると、次の問題が発生します。メモリ内のデータベースで作業しています (この目的で h2 と hsqldb を使用しましたが、どちらも同じエラーになります)。
次の hibernate.cfg.xml ファイルがあります。
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:mem:news;INIT=create schema IF NOT EXISTS news</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="show_sql">false</property>
<mapping resource="com/mycom/common/List.hbm.xml"></mapping>
<mapping resource="com/mycom/common/Info.hbm.xml"></mapping>
<mapping resource="com/mycom/common/User.hbm.xml"></mapping>
<mapping resource="com/mycom/common/Category.hbm.xml"></mapping>
<mapping resource="com/mycom/common/Topic.hbm.xml"></mapping>
<mapping resource="com/mycom/common/CategoryRelation.hbm.xml"></mapping>
<mapping resource="com/mycom/common/TopicRelation.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
CategoryRelation.hbm.xml と TopicRelation.hbm.xml の目的は、Category/Topic テーブル (マスター データ テーブル) と他のテーブルの間のマッピングを含む単なる中間テーブルです。
sessionFactory の作成中に hbm2ddl を使用してデータベースを自動生成すると、次の問題が発生します。
2012-10-16 16:36:35,448 DEBUG [main] com.mchange.v2.c3p0.impl.NewPooledConnection - com.mchange.v2.c3p0.impl.NewPooledConnection@af4627 handling a throwable.
org.h2.jdbc.JdbcSQLException: Table "T_RELATIONTOCATEGORY" not found
t_relationtoTopic についても同様です。
CategoryRelation.hbm.xml ファイルの抜粋
<hibernate-mapping>
<class name="com.yell.news.model.CategoryRelation" table="t_relationToCategory">
...
</hibernate-mapping>
これに fk を持つその他の抽出
<hibernate-mapping>
<class name="com.mycom.myapp.model.List" table="t_List">
...
<set name="categoryRelation" fetch="join" table="t_relationToCategory" lazy="false" inverse="true" >
<key>
<column name="rec_ListId"></column>
</key>
<one-to-many class="com.yell.news.model.CategoryRelation"/>
</set>
</class>
</hibernate-mapping>
何が問題なのですか?