You have two separate applications. Each has its own instance of the hibernate SessionFactory, and therefore its own copy of the second-level cache. (Go read up on caching, this is pretty straightforward.)
So, no matter what kind of autocommit/transactional scheme you use, the second level caches of each application will get out of sync. You need to use some kind of "shared" or "clustered" cache for your application. You can use JBoss TreeCache, SwarmCache, or OSCache (with a patched Cache provider). Each of these caches are capable of communicating cache events between the caches. TreeCache uses a granular approach, whilel OSCache and SwarmCache use a "clustered eviction" strategy. I've used both TreeCache and OSCache will success.
The default cache used by Hibernate is EHCache, which will not provide intra-application caching. There's plenty of material on using all three of those caches. Go do some reading and some experimentation, and then post if you get stuck.
|