Thanks Oskar for your answer. Writing the code in Business Layer is an option. My question however was that is there any way to define something in the HBM files so that the deletion of the last child will trigger a deletion of the parent.
For example take the case of Order(Parent Table) and OrderLines(Child Table) Order cannot exist without any OrderLines. My requirement is if all the OrderLines are deleted individually one by one from the OrderLine Table(Child) then after the last OrderLine entry is deleted the Order entry also gets deleted from the Order Table(Parent). In a bi-directional relationship is there any way to do it? On Mon, Aug 6, 2012 at 7:18 PM, Oskar Berggren <[email protected]>wrote: > cascade=delete will delete the collection members when the parent is > deleted, not "when all parents are deleted". > > Either you implement this requirement as business logic in a > "DeleteUserService" or "DeleteUserCommand". Either directly, or have the > "DeleteUserCommand" emit a "UserDeletedEvent" which will be handled by the > "RemoveEmptyGroupsHandler". Or you might use the event or interceptor > framework in NHibernate to add a check for this. > > > /Oskar > > > > > 2012/8/6 Sudripto <[email protected]> > >> I have the following Parent Child Relationship involving two >> tables/entities. Group(Parent) and User(Child). The Mapping is as follows. >> Now there is a requirement where I have to delete a Group entry from the >> parent table when the last last child i.e. User entry of that particular >> Group is deleted from the child table. I added cascade=delete in the child >> table but that is not giving correct result. Any possible other solution? >> >> *Parent Table:* >> <class name="Group" table="Group" lazy="true" > >> <id name="Id"> >> <generator class="identity /"> >> </id> >> <property name="Name"> >> <column name="Name" sql-type="nvarchar" not-null="true" /> >> </property> >> * <bag name="Users" inverse="true" cascade="all"> >> * >> * <key column="GroupId" />* >> * <one-to-many class="Group" />* >> * </bag>* >> </class> >> >> *Child Table:* >> <class name="User" table="User" lazy="false" > >> <id name="Id"> >> <generator class="identity" /> >> </id> >> <property name="FirstName"> >> <column name="FirstName" sql-type="nvarchar(MAX)" not-null="true" /> >> </property> >> ............................... >> ............................... >> * <many-to-one update="false" not-null="true" **name="Group"> // >> added cascade delete here but that is not working* >> * <column name="GroupId" />* >> * </many-to-one>* >> </class> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/nhusers/-/2sZYxy9dJBYJ. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
