I've a problem with NHib, I've two objects, which are connected in parent child association, I create the parent and save it to the database, then I add the child, flush everything, and tries to delete the parent.
NHibernate tries to issue an update of the child to set it's parent column to null (which cause constraint violation).
I checked the refenrence, and as far as I can say, I'm doing everything as I should.
As far as I can tell, it should issue a delete statement for the child and the delete the parent.
Here is the code:
Code:
[Test]
public void AddQueryAndThenDelete()
{
ISession s = repository.Session;
Project project= new Project(projectName);
s.Save(project,2);
Query q = new Query("first query","first query text");
project.Queries.Add(q);
q.OwnerProject = project;
s.Flush();
s.Delete(project);
s.Flush();
}
Here are my mapping files:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Ayende.NHibernateQueryAnalyzer.Model.Project, Ayende.NHibernateQueryAnalyzer.Core" table="projects">
<id name="Id" column="id" type="Int32" unsaved-value="0" access="nosetter.camelcase">
<generator class="identity" />
</id>
<property name="Name" column="name" type="String" access="nosetter.camelcase" length="255" />
<set name="Queries" cascade="all-delete-orphan" inverse="true">
<key column="project_id"/>
<one-to-many class="Ayende.NHibernateQueryAnalyzer.Model.Query, Ayende.NHibernateQueryAnalyzer.Core"/>
</set>
<bag table="files" name="Files" access="nosetter.camelcase" lazy="true">
<key column="project_id"/>
<element type="String" column="filename" />
</bag>
</class>
</hibernate-mapping>
And the second:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Ayende.NHibernateQueryAnalyzer.Model.Query, Ayende.NHibernateQueryAnalyzer.Core"
table="Queries">
<id name="Id" column="id" type="Int32" unsaved-value="0" access="nosetter.camelcase">
<generator class="identity" />
</id>
<property name="Name" column="name" type="String" length="255" />
<property name="Text" column="text" type="String" />
<many-to-one
not-null="true"
name="OwnerProject"
column="project_id"
class="Ayende.NHibernateQueryAnalyzer.Model.Project, Ayende.NHibernateQueryAnalyzer.Core" />
</class>
</hibernate-mapping>