-->
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.  [ 1 post ] 
Author Message
 Post subject: association mapping problem using DAO
PostPosted: Sat May 15, 2004 3:45 am 
Beginner
Beginner

Joined: Sun May 09, 2004 7:18 pm
Posts: 35
I have a many to many association between two tables: STUDENT and
COURSE. I also have an association table say STUDENT_COURSE which contains sid and cid.
I used middlegen to generate the mapping files and persistent class
automatically.I get student.class, sc.class and course.class. I also get
student.hbm.xml,

<!-- associations -->
<!-- bi-directional one-to-many association to STUDENT_COURSE-->
<bag
name="STUDENT_COURSE"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="SID" />
</key>
<one-to-many
class="STUDENT_COURSE"
/>
</bag>

course.hbm.xml
<!-- associations -->
<!-- bi-directional one-to-many association to STUDENT_COURSE-->
<bag
name="STUDENT_COURSE"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="CID" />
</key>
<one-to-many
class="STUDENT_COURSE"
/>
</bag>

The problem occurs when I do add and delete. Using studentDAO.add(student)
and courseDAO.add(course) are quite straightforward. When I try to set up
the relation between student and course, I have to create cs object first
and then call Student_CourseDAO.add(cs). In the Student_CourseDAO, I not only do student.getcs.add(cs), course.getcs.add(cs). I also have to do
session.add(student_course) which is supposed to be transparent implemented by Hibernate.

When I try to delete a student record, the cs record referenced by it are
not deleted at all. I have to traverse the list and manually delete them
one by one. And the list in course still keeps the reference for those
records in student_course. I am totally lost in deletion.

Could anybody please give me any hint on this situation?

thanx a lot.

Ping


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

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.