I am testing concurrent updates on Grails domain objects. I am consistently seeing stale object data, including version, when fetching a domain object using dynamic finders in a session & thread exclusive region as if the newly fetched object is an old object in cache. As I understand Grails/Hibernate, Dynamic finders should ensure we fetch data from the database and not a cache. In order to determine if caching was the problem, I disabled the hibernate cache as follows: hibernate { cache.use_second_level_cache = false cache.use_query_cache = false // cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3 cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4 singleSession = true // configure OSIV singleSession mode flush.mode = 'manual' // OSIV session flush mode outside of transactional context } Despite disabling caching I am still seeing stale object data. How can this possibly happen? I am currently running on Grails version 2.5.4 Example code flow: 1) Session 1 enters exclusive region, fetches domain object with dynamic finder and saves update. version = 0 before update, version = 1 after update. 2) Session 2 enters exclusive region, fetches domain object with dynamic finder and saves update. version = 1 before update, version = 2 after update. 3) Session 1 renters exclusive region and fetches the domain object with a dynamic finder. The domain object version = 1 before update even though the database clearly indicates version = 2. Upon saving we see an optimistic locking failure occurs showing the version is actually 2. |