-->
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: ManyToMany delete
PostPosted: Wed Jun 16, 2010 6:38 am 
Newbie

Joined: Tue Dec 22, 2009 8:38 am
Posts: 18
Hello everyone,

I have a regular ManyToMany association Student-Klass. And I am interested how could delete a Student, deleting the corresponding Klasses (not only the references from Student to Klass)

At the database level, I have three tables: Student(Id, Name), Klass(Id, Name), StudentToKlass(Id, StudentId, KlassId).

At the persistence layer level, I have 2 classes: Student(Id, Name, IList<Klass> Klasses) and Klass(Id, Name, IList<Student> Students).

The ManyToMany mapping is done the following way:
- For the class Student:
<idbag name="Klasses"
table="StudentToKlass"
lazy="true"
cascade="none">
<collection-id type="Int32" column="Id">
<generator class="identity" />
</collection-id>
<key column="Student" />
<many-to-many
class="Klass" column="Klass"></many-to-many>
</idbag>
- For the class Klass:
<idbag name="Students"
table="StudentToKlass"
lazy="true"
cascade="none">
<collection-id type="Int32" column="Id">
<generator class="identity" />
</collection-id>
<key column="Klass" />
<many-to-many
class="Student" column="Student"></many-to-many>
</idbag>

I have chosen the idbag mapping due to projects requirements. Also due to projects requirements, the association Student-Klass is bidirectional.

I want that when I delete a Student object, delete also the associated Klass objects (the corresponding records in table Klass), not only the references to it (the corresponding records in table StudentToKlass). Is this possible ?

Please advise if you have experiences a similar problem. I could provide also more details if required.

Thank you,
C.


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.