Hibernate Caching/Browser display of stale data

Hi all,

I use DBVA for Generation of ORM code, which is based on Hibernate, as is known.

Now when I change data in one of my application’s form, I usually perform following steps:

  • t = PersistentManager.instance().getSession().beginTransaction();
  • save those objects by object.save()
  • t.commit();
  • PersistentManager.instance().getSession().flush();
  • PersistentManager.instance().getSession().evict();

Now when I look at my reloaded form resp. its data, everything looks fine, the changed data is visible. But sometimes (not always) the unchanged, thus stale data is shown, even after the page had shown the correct, new data once. (That is within one JSP-session.)

How can that happen?? After reloading the page a number of times (by pressing CTRL-R in Firefox) the correct data is shown again.

I have disabled browser-cache by putting in my header (on each page, resp. all pages have a common header):

Now my questions are:

  • Does this have anything to do with Hibernate/the DBVA generated code at all?
  • Is this more likely to be a question of erroneous browser behaviour!?
  • Does anyone by chance have any ideas how to improve my situation??

I’m glad I found the hints regarding evict() at all, and the DBVA documentation on the java_orm/flushing_objects page here on the resource section - after searching for a while.

And I was glad that I had seemingly solved my caching problem, but now I see that it hasn’t been solved fully.

Can anyone help?

Regarding browser-caching there are tons of resources on the net, but they are often outdated or misleading, and before I search in that direction I want to make sure that I’m not missing anything else.

Thanks in advance to anyone who can help.

Next I’ll try the way of closing and reopening an ORM session, as described in the resources-documentation. But I’m not very hopeful that that will change anything.

Try session.clear() instead of session.evict(object).

Meanwhile I’ve found out that WebSphere Application Server Community Edition and the regular WAS behave a lot differently.

On WASCE it worked fairly well with closing and reopening a session.

On WAS evict() works fine.

Maybe just a configuration problem. Just as a hint…