我在尝试执行单元测试时遇到以下问题。我正在使用内存中的数据库(为此我使用了 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>
知道可能是什么问题吗?