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: One shot delete problem
PostPosted: Mon Sep 08, 2008 7:49 am 
Beginner
Beginner

Joined: Thu Apr 27, 2006 5:49 am
Posts: 31
Today I have checked what sql queries are generated after I call session.Delete method on one of my objects. To my surprise I've got more then 100 queries and most of them (95 to be precise) are just executing of delete statement for child objects. I want to reduce number of delete queries and make sure that for each associated collection of my root object I get only one delete statement.

I found that NHibernate 1.2.1.400 supports one shot delete strategy for child collection. I also checked http://jira.nhibernate.org/browse/NH-999 issue and I am sure that my mapping is okay. But after committing the transaction I am getting sql constraint exception, which says that parent object tried to be deleted before deleting child objects.

My code looks similar to:
Code:
  myRoot.ChildCollection = new ArrayList();
  session.Delete(myRoot);
  transaction.Commit();


Is there anything else in the mapping I should check except cascade and inverse properties? Should every collection be mapped as cascade="all" inverse="false" for supporting one shot delete strategy? Is it also required for collections associated with base class of my root entity even if I don't need them to be deleted in one-shot (there is a small quantity of elements in the base class collection, so I don't care if the delete statement executes for each item)?


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.