OK, I give the answer, as it turns out to be working now. After I update the category in SessionB, I make the view-model owning SessionA to successively do an Evict and a Refresh on the category.
Moreover, I changed the unidirectional one-to-many to bidirectional. But I don't have to set on-delete="cascade". Thanks again for your answer :) On 5 déc, 19:20, Michael <[email protected]> wrote: > Thanks for your answer. > > I did like you wrote, but I still have the same exception. > > How should I update the category within SessionA after it has been > updated in SessionB? > > I've tried various combinations of Evict / Refresh / Merge, but with > no success. > > Thanks in advance > > Michael > > On 5 déc, 12:48, Fabio Maulo <[email protected]> wrote: > > > > > > > > > because it seems completelly possible, you have to trasform the > > relation from a unidirectional-one-to-many to a > > bidirectional-one-to-many (where delete orphans really work because > > there is a parent); then you have to map the one-shot-delete > > (on-delete="cascade") > > > -- > > Fabio Maulo > > > El 04/12/2010, a las 21:41, Michael <[email protected]> escribió: > > > > Hello all, > > > > here are my two entities: > > > > public class VideoCategory : BaseEntity<VideoCategory> > > > { > > > private readonly Iesi.Collections.Generic.ISet<VideoFolder> > > > folders = new HashedSet<VideoFolder>(); > > > > public VideoCategory() > > > { > > > > } > > > > public VideoCategory(string name) > > > { > > > Name = name; > > > } > > > > public string Name { get; set; } > > > > public IEnumerable<VideoFolder> Folders { get { return > > > folders; } } > > > } > > > > public class VideoFolder : BaseEntity<VideoFolder> > > > { > > > private string path; > > > private readonly Iesi.Collections.Generic.ISet<VideoFile> videos = > > > new HashedSet<VideoFile>(); > > > > public VideoFolder() > > > { > > > > } > > > > public VideoFolder(string path) > > > { > > > Path = path; > > > } > > > > public string Path { get; set; } > > > public string Name { get; private set; } > > > } > > > > There is a Many-To-One relationship from VideoFolder to VideoCategory, > > > with a Cascade.AllDeleteOrphan. > > > > Here is how the problem happens: > > > > I create a new instance of VideoCategory, and save it in SessionA. > > > Once created, the id of this category is published to another view- > > > model, which queries the database to load the entity, in SessionB. > > > > In SessionB, I create a new VideoFolder, add it to the category, and I > > > update the category in SessionB. > > > > Now back in SessionA, if I then want to delete VideoCategory, I have > > > this exception: > > > > "The primary key value cannot be deleted because references to this > > > key still exist" > > > > I think it's normal, because SessionA doesn't know that the category > > > now has some folders. > > > > I've added a step which allows the first view-model, owning SessionA, > > > to update the category after it has been updated by SessionB, before > > > it deletes the category, and in that step: > > > > * I've tried to call Session.Merge, but I have : NonUniqueException : > > > a different object with the same identifier value was already > > > associated with the session:1, of entity VideoCategory > > > * I've tried to evict the category, then merge it, but I have the same > > > exception. > > > > How can I resolve my problem? > > > > Thanks in advance > > > > Michael > > > > PS: if I add the category, then add a folder to the category, then > > > close the view-model, then open it again and delete the category, I > > > don't have the exception > > > > -- > > > 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 > > > athttp://groups.google.com/group/nhusers?hl=en. -- 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.
