views:

208

answers:

1

I have two applications running on a machine, where NHibernate is used as an ORM. One app is managing objects (CRUD operations), while the other is processing the objects (get, process, set status and save).

First I let the processing app process an object and set the status to processed. Then I change a text property manually in the database and reset the status (to make it process it again). The manual DB edit is to simulate the managing app. Then I start to see problems:

  1. The read object still has the old text property, event though I've changed it in the DB. I guess NHibernate caching is the problem here.

  2. When I set the object's status to processed, it uses all properties in the where clause when updating, which means it doesn't get updated in the database. This is because it has the wrong text in a property. I would guess this also has to do with caching.

The consequence of the status not being updated is that the same object (with wrong text) is processed over and over and over...

Anyone out there who can help me with how I should set up NHibernate to make this problem disappear?

A: 

Better call refresh method on the object you want, because flush can have unwanted side-effects.

Bozho
what side effects?
Dead account
You mean Session.Refresh(obj)? I guess a trip to the database has already been made when running the criteria, so that would cause an extra trip to the database for every object, right? That sounds like a bad thing to do from a performance perspective.Can't I do something in the criteria when getting a whole bunch of objects to process?
Kristoffer