Thanks guys you pointed to the problem. I've used an ISet instead and it's working much better now. Oskar, would there be a benefit over ISet if I used an idbag ?*
Thanks On Oct 5, 11:42 pm, Oskar Berggren <[email protected]> wrote: > I believe using idbag instead of bag will solve this, especially since > you already have "BuzzUserFavouritesID". > > /Oskar > > 2009/10/5 Roger Kratz <[email protected]>: > > > > > From manual... > > "Since a bag permits duplicate element values and has no index column, no > > primary key may be defined. NHibernate has no way of distinguishing between > > duplicate rows. NHibernate resolves this problem by completely removing (in > > a single DELETE) and recreating the collection whenever it changes. This > > might be very inefficient." > > >http://www.nhforge.org/doc/nh/en/index.html#performance-collections-t... > > > ________________________________________ > > Från: [email protected] [[email protected]] för > > graphicsxp [[email protected]] > > Skickat: den 5 oktober 2009 17:14 > > Till: nhusers > > Ämne: [nhusers] nhibernate deletes all my record before inserting > > > Hi, > > > I have an entity which holds a collection of other entites. In the > > database this tranlates to 3 tables. > > > [BuzzUser] {BuzzUserID, Name} > > [BuzzUserArt] {BuzzUserArtID, Title} > > [BuzzUserFavourites]{BuzzUserFavouritesID, BuzzUserID, BuzzUserArtID} > > > In the mapping of BuzzUser, I've mapped the third table to a bag : > > > <bag name="Favourites" table="BuzzUserFavourites" lazy="false"> > > <key column="BuzzUserID" /> > > <many-to-many class="BuzzArt.BuzzUserArt, BuzzArt" > > column="BuzzUserArtID" /> > > </bag> > > > Now if I add a BuzzUserArt entity to the collection Favourites : > > > if (! buzzUser.Favourites.Contains(buzzUserArt)) > > buzzUser.Favourites.Add(buzzUserArt); > > > _buzzUserDao.SaveOrUpdate(buzzUser); > > > Then NHibernate deletes all the favourites associated to this > > BuzzUser : > > > DELETE FROM BuzzUserFavourites > > WHERE BuzzUserID = '306170f2-737f-402c-9731-9c63013c32db' > > > and then it adds them all again, including the one I wanted to add > > initially : > > > INSERT INTO BuzzUserFavourites (BuzzUserID, BuzzUserArtID) VALUES > > (@p0_0, @p1_0) > > INSERT INTO BuzzUserFavourites (BuzzUserID, BuzzUserArtID) VALUES > > (@p0_1, @p1_1) > > > It seems inefficient to me. What am I doing wrong ? > > > Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
