Hi. I'm using Hibernate 3.2.5 with an EHCache.
The code below, on an entity declared with a <version> in it's mapping, fails with StaleObjectStateExceptions that I can't seem to recover from, even though I try many times to reload the current state.
Code:
// update service statistics when a resource is fetched from a resource manager
for(int attempts = 1; attempts <= lockRetryAttempts; attempts++) {
    try {
        session.evict(manager);
        manager = (ResourceManager) session.load(ResourceManager.class,
            manager.getId(), LockMode.READ);
        // sleep for a few seconds here to highlight concurrent updates
        manager.setFetchedBytes(manager.getFetchedBytes() + resource.getSize());
        manager.setFetchedFiles(manager.getFetchedFiles() + 1);
        session.flush();
        break;
    } catch(StaleStateException e) {
        if(attempts == lockRetryAttempts) {
            throw e;
        }
    }
}
So, how can I get Hibernate to do what I'm trying to do? Which is, when catching a StaleObjectStateException, to force it to reload the record and try again.