Just realised the issue is to do with the unique constraint. NHibernate seems to be trying to delete the child object *after* doing the insert for the new child... but because it has the same unique key elements, you break the unique constraint.
Is there a way to force NHibernate to do the deletes first? Thanks James 2009/4/1 James Crowley <[email protected]> > I have a parent object which has a one to many relationship with an ISet of > child objects. When deleting a child object, *everything works fine*. But > when deleting a child object *and* adding a new child object in the same > transaction, the first child is not deleted. > > I have the following in the parent object: > > <set name="Pages" inverse="true" cascade="all-delete-orphan" > access="field.camelcase-underscore"> > > <key column="ContentId" /> > > <one-to-many class="DeveloperFusion.Domain.Entities.ContentPage, > DeveloperFusion.Domain, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" /> > </set> > > My code is as follows: > > Content content = contentRepository.Get(1); > > content.Pages.Clear(); > //--- > //If I un-comment this, everything works as expected > //NHibernateSession.Current.Flush(); > //--- > > content.Pages.Add(new ContentPage("Some new title", 1, "Some content") }); > NHibernateSession.Current.Update(content); > NHibernateSession.Current.Flush(); > > basically no delete statement is being executed for the page element that > has been removed. However, if I don't combine the adding and the deleting > (by uncommenting the Flush() statement) everything works fine. > > What am I missing??? > > Thanks > > James > > -- James Crowley Managing Director Developer Fusion - Connecting developers worldwide Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH mob: 07986 624128 web: http://www.developerfusion.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
