-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Bi-directional mapping problems while creating tables on run
PostPosted: Wed Jan 17, 2007 4:36 am 
Newbie

Joined: Fri Jan 12, 2007 8:04 am
Posts: 4
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 everthing is working fine, but that requires changes in my code, can anybody suggest other options.

Thanks,
Nag


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 2:35 am 
Newbie

Joined: Fri Jan 12, 2007 8:04 am
Posts: 4
If i modify the mapping as mentioned below in students table, then the table creation happens.

<set name="courses" table="student_course" cascade="save-update">
<key column="student_id" />
<one-to-many class="StudentCourse" />
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 2:36 am 
Newbie

Joined: Fri Jan 12, 2007 8:04 am
Posts: 4


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.