I've been away from NHibernate for a long time, so my recollection may not be 100% accurate here. But I believe the bag may be the issue. Change to use a set instead of a bag and see if that resolves the issue. Do you really want bag behavior, are you just using a bag so you can map to IList? If you do not want duplicates in the collection, such as details of an order, stops on a route, children of a person, employees of a manager, you are better off with a set.
On Sun, Apr 5, 2009 at 2:06 PM, graphicsxp <[email protected]>wrote: > > Could someone help with this issue ? I've searched online but I' m > under the impression that I've done the right thing, i.e. I put > inverse=true in the bag collection .. > I'm saving a Post which has 30 Comments and NH does an update 30 > times, no update should be required at all.... > > On 3 avr, 14:48, graphicsxp <[email protected]> wrote: > > Hi, > > > > I'm using NHProfiler to profile my NH activity and I'm getting the > > warning: > > > > superfluous <many-to-one> update - use inverse = 'true' > > > > I have two classes, Post and Comment, here is the mapping : > > > > Post.hbm.xml : > > > > hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> > > <class name="Metrica.Post, Metrica" table="Post" lazy="true" > > discriminator-value="POST" abstract="true"> > > <id name="Id" column="PostID"> > > <generator class="native"/> > > </id> > > > > <discriminator column="Type" type="string" /> > > > > <property name="DateCreated" type="date" column="DateCreated" > > insert="false" generated="always" /> > > > > <property name="Headline" type="string" length="500" > > column="Headline" /> > > <many-to-one class="Metrica.Publication,Metrica" > > name="thePublication" cascade="none" column="PublicationID" /> > > <property name="URL" type="string" length="1000" column="URL" /> > > <property name="AnalystComment" type="string" > > column="AnalystComment" /> > > <bag name="Comments" inverse="true" cascade="all" lazy="true"> > > <key column="PostID" /> > > <one-to-many class="Metrica.CommentPost, Metrica" /> > > </bag> > > </class> > > > > Comment.hbm.xml: > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> > > <class name="Metrica.CommentPost, Metrica" table="Comment" > > lazy="true" discriminator-value="COMMENT" > > proxy="Metrica.CommentPost,Metrica" > > > <id name="Id" column="CommentID"> > > <generator class="native"/> > > </id> > > > > <discriminator column="Type" type="string" /> > > > > <property name="DateCreated" type="date" column="DateCreated" > > insert="false" generated="always" /> > > > > <many-to-one name="thePost" class="Metrica.Post, Metrica" > > cascade="none" column="PostID" not-null="true" /> > > > > </class> > > </hibernate-mapping> > > > > I don't see where I should add inverse=true in order to avoid all the > > UPDATE statements that occur when I save a Post : > > > > UPDATE Comment SET PostID = @p0 WHERE CommentID = @p1 > > > > (called as many times as there are comment entities associated to the > > post entity ! ) > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
