Hi Folks,
I know this has come up a few times before - I've looked at some of the other threads on this issue but nothing has seemed to help much.
I'm developing an "online shop" web application and I've run into a curious issue in which I occasionally get an out-of-date version of model data from Hibernate. I'm using the open session in view pattern, opening the session when an http request hits my control servlet and closing it again with a filter once my view has finished rendering. This seems to occur when I'm adding an item to the basket - I'll add an item (the hibernate session opens, associations between product, basket item, basket etc are updated before the hibernate session is finally closed). Often when the page reloads (new hibernate session opens, stuff is pulled out of the model, view is rendered, session is closed) I won't see my item in the basket! If I hit refresh in the browser, it usually appears. Sometimes it takes a couple of refreshes...
I know it's not a browser caching issue, as if I put a break point in my code I can see the "stale" data coming back through the Hibernate session. I've experimented with changing the transaction isolation level, but it doesn't seem to have much of an impact (unless I use 'serializable', but that's really not a realistic option).
I've tried other clutching-at-straws stuff such as disabling the query cache, and the second level cache, and also explicitely 'evicting' the hibernate managed objects that I'm updating from the session cache, but again none of this has really had a notceable impact.
If anyone has any ideas, or anything else to try I'm all ears!
Many thanks, Richard.
I'm using Hibernate 3.3.1, MySQL 5.x, Tomcat 5.5.27 & J6SE
|