NHibernate isn't retrieving manually changed data?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

There are two types of caches in nhibernate: session caches and second-level caches. The session cache is always caching objects seen by that session - it's how nhibernate knows which objects have changed and need to be persisted. The second-level cache, which you disabled, is below that.

The information you're seeing cached is coming from the session cache If your application needs to see changes persisted by other sources (say, manual database changes), the answer is probably to create sessions at a finer granularity. While a SessionFactory lives for the life of your application, a Session object should be created much more often. For example, in a web application, every request generates its own session If that's not an option, session.Clear() will evict all objects from the session.

There are two types of caches in nhibernate: session caches and second-level caches. The session cache is always caching objects seen by that session - it's how nhibernate knows which objects have changed and need to be persisted. The second-level cache, which you disabled, is below that.

The information you're seeing cached is coming from the session cache. If your application needs to see changes persisted by other sources (say, manual database changes), the answer is probably to create sessions at a finer granularity. While a SessionFactory lives for the life of your application, a Session object should be created much more often.

For example, in a web application, every request generates its own session. If that's not an option, session.Clear() will evict all objects from the session.

I don't know whether it will solve the problem you're having, but the documentation states: To completely evict all objects from the session cache, call ISession.Clear() For the second-level cache, there are methods defined on ISessionFactory for evicting the cached state of an instance, entire class, collection instance or entire collection role. If you did this every time you did something that executes a SELECT on data likely to change out of band, it should do what you want.

I think you're going to have to be a bit more descriptive of your exact problem to get an answer; I have some minimal experience with nhibernate, but I can't really go about replicating what's going on and try to fix it without, say, some code.

Srry for being too specific Nhibernate is retrieving data without any problem. But When I manually change data in a repository table. The Icriterea(nhibernate) is sometimes picking up from cache or from the table.

I am using Icriteria funcnality: ICriteria criteria = session. CreateCriteria(typeof(xyzclass)); criteria. Add(Expression.

Eq("xyzclass", somestringto retreivedata)); criteria. SetCacheable(false); return criteria.UniqueResult().

I've never actually used the caching features of N but I believe the intent of it is to remove the need to go to the database at all, meaning it wouldn't pick up manual changes because it doesn't know about them. I'd question exactly what it is you're trying to achieve here, are you just doing some testing by manually editing the database or will this be a regular activity in a live application? Really, the only thing that should be modifying your database is the application, doing so through your N therefor updating and/or dirtying the cache in the process.

Ts is just part of testing. But in the future we could edit the datatable manually. I have also set lazy to false for that table and commented out all the second level cache properties used by hibernate.

But even then it is returning me different values instead of newly edited value. Sometimes it is giving me old value and sometimes the new, so it is not constant.

A good relation with Nbernate always depends on strong OO commitment and at most common cases depends on data changes exclusivity. If you don't have it you'll see some nasty problems and will give up most of the really nice things NH could offer. Lets say there is a class called "Foo" mapped to a table "Foo" with columns "Id" and "SomeProperty".

If all rows have "SomeProperty" manually updated from "oldValue" to "newValue" and NH sends some query to DB asking for all Foos where SomeProperty = "newValue", the DB returns all Foos, as expected. But Foo instances NH delivers may have "oldValue" because Foo with the returned Id was already attached to the session (on other words, it was on 1st level cache). The only short way to make Nbernate be aware of all manual updates is using StatelessSesion, so it won't cache object instances and will always deliver the DB version of data.

But if you want to apply this on a transactional system its a clear sign of unappropriate use of NH and you won't obtain most of nice NH features.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions