Hi I'm having a problem updating child objects in the following scenario.
The mappings are as follows:
Parent: Calendar
<bag name="defaultCategories" inverse="true" lazy="false"
cascade="all-delete-orphan">
<key column="parentID" />
<one-to-many class="DefaultCategory"/>
</bag>
Child: DefaultCatergory
<class name="DefaultCategory" table="tb_calendar_default_category" lazy="false">
<id name="id" column="id">
<generator class="hilo"/>
</id>
<many-to-one name="calendar" column="parentID" not-null="true"
cascade="all-delete-orphan" />
Code used to update calendar:
public Calendar Update(Calendar vo)
{
session = NHibernateHelper.GetCurrentSession();
tx = session.BeginTransaction();
using (tx)
{
session.Update(vo);
tx.Commit();
}
return vo;
}
The problem is that when I add or delete defaultCategories via the ui and send back the updated version of the calendar to the back end, NHibernate returns the updated calendar and all seems well. However any defaultCatergories which should have been deleted are left in the default Categories table. Thus when I refresh the ui and call for the calendar again, I can see collection has not changed.
Do you think I need to delete all defaultCatergories by parentID and then recreate? I was under the impression NHibernate took care of this for you? Any help or pointers much appreciated.