I havent found any solutions to my problem with "Delete", can anyone in this forum help me?
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 Professor.
Instead of having a many to many relationship, I am using many-to-one and one-to-many. The reason is that the Professor table must contain arbitrary data. Also, this is the recomended way according to documentation.
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 I am going to delete in the 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 Professor table before deleting the Person.
Of course could I manually delete the object in the Professor table,,,,,,, but I prefer to let the NHibernate do the job.
Department:
Code:
...
...
<bag name="Professor" inverse="false" table="Professor" cascade="all-delete-orphan" lazy="false" >
<key column="ProfId"></key>
<one-to-many class="Professor,asm"/>
</bag>
...
...
DepartmentProfessor (Table Professor )
Code:
....
....
<many-to-one column="Person" name="Person" 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="Person"></key>
<one-to-many class="Professor,asm"></one-to-many>
</bag>
....
....
What am I doing wrong?
//regards Lasse