Hi.
I have a problem deleting objects. The setup is like,,, a Department can have many Professors.
I have a table for the department, and a table for persons. Linking them together I have a table called Department Professor.
Instead of having a many to many relationship, I am using many-to-one and one-to-many. The reason is that the Department Professor table must contain arbitrary data.
My problem is... when deleting a Person,,, I get an error saying that I am breaking a reference constraint. There is a reference to the person in the Department Professor table.
To me it seem like NHibernate is deleting objects in the wrong order. It should have been deleting the referenced object in the Department Professor table before deleting the person.
Of course could I manually delete the object in the Department Professor table,,,,,,, but I prefer to let the NHibernate do the job.
What am I doing wrong?
//regards Lasse
Departments:
Code:
...
...
<bag name="Professor" inverse="false" table="Professor" cascade="all-delete-orphan" lazy="false" >
<key column="ProfId"></key>
<one-to-many class="ClassProfessor,asm"/>
</bag>
...
...
Department Professor:
Code:
....
....
<many-to-one name="Item" class="Person, asm" cascade="save-update" lazy="false"></many-to-one>
....
....
Person:
Code:
....
....
<bag name="Professor" inverse="false" table="Professor" cascade="all-delete-orphan" lazy="false">
<key column="Item"></key>
<one-to-many class="DepartmentProfessor,lgTronic.Spada.Business.Entities"></one-to-many>
</bag>
....
....