File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes Bi-directional mapping problems while creating tables on runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Bi-directional mapping problems while creating tables on runtime " Watch "Bi-directional mapping problems while creating tables on runtime " New topic
Author

Bi-directional mapping problems while creating tables on runtime

nagaraj kris
Greenhorn

Joined: Jan 12, 2007
Posts: 5
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
 
Don't get me started about those stupid light bulbs.
 
subject: Bi-directional mapping problems while creating tables on runtime