Merge changes in Nhibernate

Considering that I have a scenario where two users are simultaneously editing a different address object. *

User 1 edits address.streetname and saves, and User 2 edits .town and saves.

Is there anyway I can configure nhibernate so that only changed fields are updated and thus the changes are merged?

I have linked dynamic update but it doesn't do the trick, the more optimization method.

dynamic-update="true"

      

I've experimented with the version as well, but that doesn't seem to have the desired effect.

<version  name="Version"  type="int" column="Version"/>

      

  • I realize this is a strange scenario, but this is the requirement that was given to me.
+2


source to share


2 answers


Strictly speaking, this is not a "merge" as such: there is always the possibility of losing data (and this is very serious, I must add). dynamic-update

should do the trick, but if you detach the object from ISession

it won't work and you will need to set select-before-update

to true

for NHibernate to re-read the specific record from the DB.



+2


source


I suggest that you request this requirement .

In the example you provided, this may be fine, but in many cases it will be functionally incompatible for mechanically merging updates without explicit functional choice.



Even in the above example, suppose you add proof by checking that a street exists in the city: your check might allow two updates to be sent and your data gets corrupted !!

+1


source







All Articles