• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bi-directional mapping problems while creating tables on runtime

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic