beranga wrote:
Options I have considered include:
1) switching caching off and relying purely on the database vendors powerful memory caching features. I am not sure if I can even switch hibernate caching off though
2) somehow running the 2xhibernate sessions in a cluster. i.e. the first session knows about the 2nd session and they share a cache.
You should turn 2nd level caching off, except read-only cache for those data that you know that noone will change (reference data etc.).
The first level cache: you cannot really turn it off (except by using a StatelessSession), nor is there a need to do so: the 1st level cache in the session is just like what is happening anyways in any application: as long as you have not committed your transaction you do have a local view that might be different from what others see. Any two applications using a database (or even any two transactions within the same application) must cope with that. Use optimistic locking to deal with that. If your other application is not using Hibernate (or not even using Java) of course it must cooperate and apply the same optimistic locking policy.
Option 2 is not really what is happening when using a clustered cache: this cache only applies to the second level cache, i.e. the level below the sessions. The 1st level cache (session) is always private (even within a single JVM).
So in any case, you must take care that you close the session (or evict all objects from it) after committing, so that re-reading objects will not reuse the cached (possibly stale) version of these. We always use the model where the lifespan of the hibernate session equals the database transaction.