The most straight forward way would be to keep track what detached entities/roots have (possibly) been modified yourself before passing them back to the data layer.
Anyhow... <<Does NHibernate always update ALL reattached objects? Or can't NHibernate determine if an Object is dirty, because it was detached from a session?>> The session need something to compare the current state of your objects. If it doesn't know this because you loaded it in another session (=no info of original state) and you do a (SaveOr)Update, the best guess it can do is to save everything (maybe there are situations when nh is smarter than that, don't know) Depending on your scenario you can... * Use session.merge. Then you will have select(s) (if 2nd level cache isn't used) before updating the changes. Might be better, might be worse. * If you run in a stateful enviroment where you know the original state, you can reassociate the original, unmodified object using session.lock before merging your detached objects to eliminate the selects. * The most straight forward in your case I would guess is what I started to write - give the new session only detached objects you know/possibly have changed. ________________________________________ Från: [email protected] [[email protected]] för reflection [[email protected]] Skickat: den 26 augusti 2009 17:53 Till: nhusers Ämne: [nhusers] Does NHibernate always update the full object graph on session.Update()? Hello, Just stumbled about a little problem: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Continental.SignalList.Domain" namespace="Continental.SignalListManager.Domain"> <class name="SignalList" table="SL_SIGNALLIST" lazy="false" optimistic-lock="version" > <id name="SignalListId" column="ID_SIGNALLIST" type="Decimal"> <generator class="sequence"> <param name="sequence">SL_SIGNALLIST_SEQ</param> </generator> </id> <version column="NH_VERSION" name="NhVersion" /> <property name="Description" type="String" column="DESCRIPTION" /> <component class="SignalCollection" name="Signals"> <many-to-one class="SignalList" name="SignalList" column="CollectionSignalList" foreign- key="fk_ColSignalList_SignalList"/> <bag name="Signals" table="SL_SIGNAL" lazy="false" cascade="all- delete-orphan" inverse="true"> <key column="ID_SIGNALLIST" /> <one-to-many class="Signal" /> </bag> </component> </class> </hibernate-mapping> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Continental.SignalList.Domain" namespace="Continental.SignalListManager.Domain"> <class name="Signal" table="SL_SIGNAL" lazy="true"> <id name="SignalId" column="ID_SIGNAL" type="Decimal"> <generator class="sequence"> <param name="sequence">SL_SIGNAL_SEQ</param> </generator> </id> <version column="NH_VERSION" name="NhVersion"/> <many-to-one class="SignalList" column="ID_SIGNALLIST" name="SignalList" foreign-key="fk_Signal_SignalList"/> <property name="PinNumber" type="String" column="PIN_NUMBER" /> <property name="ContiTevesName" type="String" column="CONTI_TEVES_NAME" /> </class> </hibernate-mapping> This is the mapping of my SignalList class. It holds another class called SignalCollection implementing the IList<Signal> Interface. It's named "Signals" in this mapping file. This class holds the mechanism to add the Signal to the internal List (also named "Signals") and to update the added signals SignalList. Something Like if(!Signals.Contains(item)) { item.SignalList = SignalList; Signals.Add(item); } If I call update on a detached object where I just changed the Description of a SignalList, it also updates all the Childs in the Signals Collection. Does NHibernate always update ALL reattached objects? Or can't NHibernate determine if an Object is dirty, because it was detached from a session? At the moment this is no big problem, because objects are very small. But I think this can get a real issue if NHibernate tries to update thousand of records just because you changed one String. Thanks for your help :) Reflection P.S.: I wouldn't mind either if anybody would have a better solution for the Collection Component :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
