Review what's happening in this line.... IAssetContent newAssetContent = newAsset.AddContent(newContent);
Since you have inverse="true" on the bag that is the collection of IAssetContent instances, you need to ensure that within the AddContent (...) method you have a line like... theContent.Asset = this; ...assuming that theContent is the IAssetContent instance passed into the AddContent(IAssetContent) method on the IAsset instance. Without acually running your code, it appears that so long as you do this, you should get the inserts in the proper order. Can you confirm (or provide the meat of the AddContent(IAssetContent) method for our review? When you call repository.Add(newContent); I suspect that the newContent instance doesn't have its newContent.Asset property correctly populated. Also, if you are going to have this persistence hierarchy, a better (and probably more common) pattern is to set the cascade="..." attribute on the bag in your Asseet mapping to allow it to persist its children vs. you having to 'remember' to call the right order of repository.Add(...) methods all the time. By calling these methods in sequence all the time, you are probably doing more work than you need to and I (generally) recommend that you let NHibernate traverse your object graph on its own and puzzle out the correct order to perform its inserts rather than you 'manually' persisting each object individually (just an opinion in this case, of course). -Steve B. On Nov 27, 9:05 am, Graham Bunce <[EMAIL PROTECTED]> wrote: > Any thoughts why > > ===> > IAsset newAsset = Factory.Create<IAsset>(); > newAsset.Name = "New name"; > > IContent newContent = Factory.Create<IContent>(); > newContent.Name = "New content"; > > IAssetContent newAssetContent = newAsset.AddContent(newContent); > newAssetContent.Quantity = 100; > > repository.Add(newAsset); > repository.Add(newContent); > repository.Add(newAssetContent); > > repository.Persist(); // All this does is a Session.Flush() wrapped > in a NHibernate transaction. > > <== > > this fails with NHibernate errors? (I know its a long original post, > but this seems pretty fundamental to me). What am I doing wrong? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
