NHibernate and Stored Procedure, Part2, dealing with orginal values

In part1, I can easily add those original values in the hbm mapping xml files. This works OK for web forms, and also no problem for one time update in win forms. But when I tried to make a repeatable update in win forms, the problem appears.

The original values in Entity objects doesn’t sync! When I called a DAO.commit(), all the changes have been made into database, and the changed columns/properties also still kept in entity objects, you think those original properties will be refreshed? No, not until you clean up the NHiberate cache manually.

Object: ID,
property: originalvalue (1)
property: realvalue (1)

Set realvalue = 2, then call Dao.CommitChanges()

Object: ID,
property: originalvalue (1) {This didn’t update! Still keep the previous original value, should be the current/original value which is 2.}
property: realvalue (2)

The solution I got is, after Dao.CommitChanges(), do a cache clean up manually.


myEntityDao.Evict( view.MyEntityToUpdate );

This made my winForm repeatable update working. An extra work is, I have to recall the initview() in UI layer, because UI needs to re-load this updated object from Dao after evict().

Again, this is a win form only issue, web form doesn’t have this problem because each page is reloaded after every commit.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s