I've been looking at my SQL Profiler output when deleting my Parent object that has a collection of children mapped as a set, and want to know if I can modify the mapping files to improve the generated SQL.
Currently, if I delete my parent object, nhibernate correctly removes the child items before deleting the parent item (thus avoiding an FK constraint error), but it does it one child at a time, instead of doing a "Delete from CHI_Child where PAR_Parent_ID = 36".
Is there any way I can improve performance here?
Many thanks in advance,
Phil
Hibernate version: 1.2.0.4000
The only code used between the start and close session is this:
Code:
//iParent references the hibernate Session
oParent = iParent.GetId(parentId);
iParent.Delete(oParent);
Mapping documents:Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" default-lazy="true">
<class lazy="true" table="[PAR_Parent]" name="MyDB.Core.Domain.DataAccess.Parent, MyDBLib">
<id name="ParentID" access="property" column="[PAR_ParentID]">
<generator class="identity" />
</id>
<set name="Children" cascade="all" inverse="true">
<key column="PAR_ParentID"/>
<one-to-many class="MyDB.Core.Domain.DataAccess.Child, MyDBLib"/>
</set>
</class>
<class lazy="true" table="[CHI_Child]" name="MyDB.Core.Domain.DataAccess.Child, MyDBLib">
<id name="ChildID" access="property" column="[CHI_ChildID]">
<generator class="identity" />
</id>
<!-- Foreign keys -->
<many-to-one name="RefParent" class="MyDB.Core.Domain.DataAccess.Parent, MyDBLib" not-null="true">
<column name="PAR_ParentID" />
</many-to-one>
</class>
</hibernate-mapping >
Name and version of the database you are using:SQL Server 2000
The generated SQL (show_sql=true):
exec sp_executesql N'DELETE FROM [CHI_Child] WHERE [CHI_ChildID] = @p0', N'@p0 bigint', @p0 = 29
go
exec sp_executesql N'DELETE FROM [CHI_Child] WHERE [CHI_ChildID] = @p0', N'@p0 bigint', @p0 = 30
go
exec sp_executesql N'DELETE FROM [CHI_Child] WHERE [CHI_ChildID] = @p0', N'@p0 bigint', @p0 = 31
go
exec sp_executesql N'DELETE FROM [CHI_Child] WHERE [CHI_ChildID] = @p0', N'@p0 bigint', @p0 = 32
go
exec sp_executesql N'DELETE FROM [PAR_Parent] WHERE [PAR_ParentID] = @p0', N'@p0 bigint', @p0 = 36
go