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.

Reply via email to