Question

I'm having the following problem while trying to execute unit tests. I'm working with a database in memory (I have used h2 and hsqldb for this purpose, but both of them drive me to the same error).

Having the following hibernate.cfg.xml file:

<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>

The purpouse of CategoryRelation.hbm.xml and TopicRelation.hbm.xml are just intermediate tables which contains a mapping between Category/Topic tables (master data tables) and other tables.

While autogenerating through hbm2ddl the database during the sessionFactory creation the following problem is raised:

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

And same for t_relationtoTopic.

Extrac of CategoryRelation.hbm.xml file

<hibernate-mapping>
 <class name="com.yell.news.model.CategoryRelation" table="t_relationToCategory">
...
</hibernate-mapping>

Extract of any other that has a fk to this

<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>

Any idea what could be the problem?

Was it helpful?

Solution

I found the solution. It seems to be a problem with the hibernate version. I was using 4.1.1.Final.

A colleague of mine told me to use 3.6.0.Final, so I added it to maven (with required library: javassist - version 3.12.1.GA) and the problem was solved.

Seems to be a problem with version 4.1.1.Final in Hibernate. Or maybe a configuration I didn't found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top