These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: To many sql deletes
PostPosted: Thu Mar 01, 2007 6:23 am 
Newbie

Joined: Sat May 14, 2005 2:17 pm
Posts: 18
I use NHibernate 1.2 RC1. And have a simple object holding a collection.
Say something like a Parent with Childeren. When I delete the parent sql is fired for every child. All I want is to delete all Childeren in one go when the parent is deleted.

mappings:

Info Class: (the parent..)

<class name="Basplus.Core.Poco.Info, BasPlus.Core" table="Infos">

<id name="Id" column="Id">
<generator class="native" />
</id>

<property name="Created" />
<property name="Validtill" />
<property name="Titel" />
<property name="Omschrijving" />

<bag name="Infoitems" cascade="all-delete-orphan" inverse="true">
<key column="InfoId" />
<one-to-many class="Basplus.Core.Poco.Infoitem, BasPlus.Core" />
</bag>

</class>

Infoitem Class (the children of Info)

<class name="Basplus.Core.Poco.Infoitem, BasPlus.Core" table="Infoitems">
<id name="Id" column="Id">
<generator class="native" />
</id>

<many-to-one name="Info" column="InfoId" not-null="true" />
<many-to-one name="Artikel" class="Basplus.Core.Poco.Artikel, BasPlus.Core">
<column name="ArtikelKey" length="6" />
<column name="DistributeurId" />
</many-to-one>
</class>


Sql fired:

SELECT infoitems0_.InfoId as InfoId__1_, infoitems0_.Id as Id1_, infoitems0_.Id as Id6_0_, infoitems0_.InfoId as InfoId6_0_, infoitems0_.ArtikelKey as ArtikelKey6_0_, infoitems0_.DistributeurId as Distribu4_6_0_ FROM basplus.dbo.Infoitems infoitems0_ WHERE infoitems0_.InfoId=@p0; @p0 = '2935'

DELETE FROM basplus.dbo.Infoitems WHERE Id = @p0; @p0 = '316891'

DELETE FROM basplus.dbo.Infoitems WHERE Id = @p0; @p0 = '316892'

DELETE FROM basplus.dbo.Infoitems WHERE Id = @p0; @p0 = '316893'

....
....

DELETE FROM basplus.dbo.Infos WHERE Id = @p0; @p0 = '2935'

So as you can see a lot of (in my eyes) useless Sql is fired. Is there a better way to do this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.