In my solution I have a branch of business objects with associations. So when I try save a root object after processing I get an exception with message \"Deleted object woul
The above solutions didn't work for me. The instance I tried to delete was nowhere referenced in my code.
However, it was in NHhibernate. After clearing the session, it worked for me.
The most common scenario (my experience) is having two root objects having collections of some pairing/middle object.
public class Employee
{
public virtual IList<Occupation> Occupations { get; set; }
}
public class Company
{
public virtual IList<Occupation> Occupations { get; set; }
}
Now, we have the Occupation
like this
public class Occupation
{
public virtual Employee Employee { get; set; }
public virtual Company Company { get; set; }
}
So, what could happen:
employee.Occupations
collection.Company
Deleted object would be re-saved by cascade
Solution(s):
Remove()
the Occupation also from company.Occupations
(do not use the cascade)
<bag name="Occupations" lazy="true" inverse="true" batch-size="25"
cascade="all-delete-orphan">
// this above setting on Company side is making issues...
<key column="Company_ID" />
<one-to-many class="Occupation" />
</bag>