Derek Beattie
Derek Beattie

Reputation: 9478

NHibernate one shot delete

I'm trying to clear a collection in a parent/child relationship by either clearing the collection (list.clear()) or creating a new instance of the collection on the parent.

Similar to this: http://markmail.org/message/mnvooa7g57dlbxta#query:+page:1+mid:mnvooa7g57dlbxta+state:results

My test is pretty much identical to the one in the link above. I've tried several combination's of settings but for the life of me I cannot get NHibernate to issues a single sql delete for all of the children as opposed to a sql delete for each child object. I must be missing something.

Upvotes: 4

Views: 1010

Answers (2)

dotjoe
dotjoe

Reputation: 26940

One shot delete could have unintended side effects so I think NHibernate plays it safe and only deletes the children that are cleared from that collection. Of course you could always use hql to write your own delete.

Upvotes: 0

zoidbeck
zoidbeck

Reputation: 4151

Interesting post. Have you tracked ayendes problem within NHibernate Jira?. I tried to and Sergey Koshcheyev marked it as 'not an issue' because of the inverse=true mapping that somehow seems to prohibit one shot delete from working, which means to me the inverse mapping prohibits the delete-orphan from working properly cause the orphans seem to be too self-contained by this. (not sure that this is the right adjective)

Try unidirectional mapping (if possible) from the parent instead to make the childs more dependent and (hopefully) one-shot deletion work.

Upvotes: 2

Related Questions