Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting old values when fetching data in Hibernate

 
Karikalan Kumaresan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am using Hibernate 3.0, Tomcat and Spring. The following is my issue,

Whenever I try to persist and query for the objects using hibernate it works fine. However sometimes it fetches the values which is different to the database (ie, old values).

Ex:
I have an object with the status "SETUP", later I changed the status of this object to "ACTIVE" and persisted the object in the database. The database reflects the latest value (which is "ACTIVE"). Again, when I try to fetch this object from the database using Hibernate, it returns the object with the status "SETUP".

Saying that, it does not happen all the time, this happens intermittently across the application. It is a bit weird.

I tried the following,

session.setCacheMode(CacheMode.IGNORE);
session.setFlushMode(FlushMode.COMMIT);

Both did not help. I am just trying to use NoCacheProvider class now. This is really causing lots of troubles in the application. Any help would be greatly appreciated.

Thanks,
Kari...
 
Jonathan Huang
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes if the object's values changed in the DB hibernate needs to refresh the Session level cache or it might use old values. This is because if the item is in the session, it'll pull it from the session instead of the DB. Try a session.refresh on your object.

http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic