Thursday, May 21, 2009

Monorail ActiveRecord and NHibernate

Ran into this at work yesterday and wanted to save others some aggravation:

Scenario: Need To query a value on a page repeatedly. Another 3rd party program is modifying the data you are querying. (in my case to generate new account numbers, could be anything)

Bad Result: 3rd Party Program changes data in background your page does not update the new value.

So my ActiveRecord query before looked something like so:


ActiveRecordMediator.FindAll(Restrictions//you don't really care do you)


now instead grab the underlying session object:


ISession session =ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(typeof(DpAcct))
var query = session.CreateQuery(//again you dont care)
var list = query.List()
session.Close()


This may not be the best way and my Nhibernate knowledge is rudimentary once you start getting into Sessions, Scopes and Flushing, but it worked to get an ActiveRecord user by.

It seems the cache doesn't know when to refresh when a third party application is involved. This is logical as the caching would be more expensive if it did.

No comments: