Hi Folks,
I'm experiencing a weird caching problem with Hibernate. I've got a fairly simple schema representing an online shop, with approximately 12 tables. After doing an update (via my hibernate code), the data gets persisted properly (I can look at the data in the DB using pgAdmin), however if I look at the data through my web browser and refresh the page a few times, I see either the old data or new data pretty much randomly. If I wait a few minutes, or restart Tomcat then I just see the new data.
I've had a look on this forum, and this appears to be the same problem -
http://forum.hibernate.org/viewtopic.ph ... ight=cache
I've disabled all caching as suggested, and this works, but it has a terrible impact on performance. I'd really like to get caching working consistently.
I've also looked at using Session.clear() and Session.refresh(Object o) in my persistence handler class, but they don't seem to have any effect. Perhaps I'm not using them correctly?
Would upgrading to Hibernate 3.2 make a difference?
Cheers,
Richard.
Hibernate version:
3.1.3
Code between sessionFactory.openSession() and session.close():
public Object persistTransaction(MergeAction action) throws Exception {
Transaction tx = null;
Session session = null;
Object mergedObject = null;
try {
session = HibernateUtil.currentSession(this.hibernateConfig);
tx = session.beginTransaction();
mergedObject = action.execute(session);
tx.commit();
session.flush();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
throw new Exception(e);
} finally {
session.close();
}
return mergedObject;
}
I have lots of implementations of MergeAction in my DAOs, but the code normally just calls session.merge(Object o) for the object I want to persist.
Name and version of the database you are using:
Postgres 8.1