rzo1 opened a new pull request, #225:
URL: https://github.com/apache/openjpa/pull/225

   https://issues.apache.org/jira/browse/OPENJPA-3022
   
   With `openjpa.DataCache=true`, loading a field of an instance that had 
unflushed changes stored those changes in the data cache. After a rollback, 
other persistence contexts read the rolled back values from the cache. This 
applies to any field type. Found by the Apache Syncope tests: a test adds an 
invalid element to a list, the validation in the DAO throws before any flush, 
the test transaction is rolled back, and later tests read the invalid element.
   
   ## Cause
   
   `DataCacheStoreManager.load()` calls `updateDataCache()` after it loaded 
fields from the database, and `cacheStateManager()` called 
`DataCachePCData.store(sm)`, which stores all loaded fields of the instance. It 
skipped flushed instances but not dirty ones. `loadAll()` did the same for 
instances that were not in the cache yet.
   
   ## Fix
   
   - New and flushed instances are not cached when they are loaded 
(`hasUncommittedState()`), in both `cacheStateManager()` and `loadAll()`.
   - For a dirty instance only its clean fields are stored 
(`storeLoadedState()`), so the fields just read from the database are still 
cached.
   
   ## Tests
   
   `TestDataCacheLoadDirtyInstance` with a new `CachedLazyEntity`: a dirty 
basic field and a dirty collection followed by a lazy load, a `findAll()` of a 
dirty instance that is not in the cache, and a flushed instance that is loaded 
or refreshed. Four of the five tests fail without the fix; the flushed-instance 
load test guards the existing skip.
   
   Full `openjpa-kernel` and `openjpa-persistence-jdbc` suites pass on Derby 
and H2.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to