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.
|