Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bi-directional mapping problems while creating tables on runtime

 
nagaraj kris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have tables with many-many relationship mapping and they are bidirectional.

I am writing junits using spring mock,DBUnit and HSQL. All the tables are created on the fly using hibernate's HBM2DDL option.

when table 'student' is getting created, i am getting exception saying table 'student_course' doesnt exist. I tried to move around the order of tables creation , but nothing is working.

Here are the mapping files

Table student:
===============
<hibernate-mapping package="test">
<class name="Student" table="student" lazy="true" batch-size="20" >
<id name="studentId" column="student_id" type="long" unsaved-value="0">
<generator class="identity"/>
</id>

<property name="name" column="name" />
<set name="courses" table="student_course" cascade="save-update">
<key column="student_id" />
<many-to-many column="course_id" class="Course" />
</set>
</class>
</hibernate-mapping>

Table course:
===============
<hibernate-mapping package="test">
<class name="Course" table="course" lazy="true" batch-size="20" >
<id name="courseId" column="course_id" type="long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="name" column="name" />

<property name="countOfStudents" lazy="true"
formula="(select count(*) from student_course sc
where sc.course_id = course_id) " />
</class>
</hibernate-mapping>

Table student_course:
==================
<hibernate-mapping package="test">
<class name="StudentCourse" table="student_course" lazy="true" batch-size="20">
<id name="studentCourseId" column="student_course_id" type="long" unsaved-value="0">
<generator class="identity" />
</id>

<many-to-one name="student" column="student_id"/>
<many-to-one name="course" column="course_id" />
</class>
</hibernate-mapping>


If i remove the set in student mapping, then everything is working fine, but that requires changes in my code, can anybody suggest other options.

Thanks,
Nag
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic