[ https://issues.apache.org/jira/browse/OFBIZ-5534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14371066#comment-14371066 ]
Adrian Crum commented on OFBIZ-5534: ------------------------------------ This issue is now a year old, and I would like to help get it resolved. Until Adam can produce his solution, I have my own that we can consider. I don't think we need to use XAResource. The problem is fairly easy to solve, so using XAResource will complicate things unnecessarily. 1. We need to add a bit of functionality to the existing transaction code: a. Associate org.ofbiz.entity.cache.Cache instances (one for each Delegator instance) to each UserTransaction instance. b. Add Publish/Subscribe (listener) functionality to TransactionUtil. Listeners are notified post-commit and post-rollback. 2. Add functionality to the Delegator: a. Make each instance a transaction listener. b. On post-commit notification, copy transaction cache to internal cache. c. On post-rollback notification, clear transaction cache. 3. Modify Delegator cache behavior: a. On find methods, check its internal cache first. b. If a miss and transaction is in place, check transaction cache. c. If a miss, execute SQL SELECT. d. If a transaction is in place, put results in transaction cache, else put results in internal cache. > Dirty reads from entity cache > ----------------------------- > > Key: OFBIZ-5534 > URL: https://issues.apache.org/jira/browse/OFBIZ-5534 > Project: OFBiz > Issue Type: Bug > Components: framework > Affects Versions: Release Branch 11.04, Release Branch 12.04, Release > Branch 13.07, Trunk > Reporter: Jacopo Cappellato > Assignee: Adam Heath > Attachments: unittest-dirtyreadsfromcache.patch > > > Even if database transaction isolation level is set to "ReadCommitted", a > transaction can get uncommitted records from the entity cache, under certain > circumstances. > Here is a test case: > 1) transaction T1 creates a record > 2) T1 calls findOne to retrieve it: the read will be successful (because T1 > can read data generated in T1 even if not committed) and the record will be > added to the cache > 3) T1 calls another service with requireNewTransaction set to true: this will > run the second service in a new transaction T2 > 4) T2 calls findOne to retrieve the record created by T1: if useCache is set > to false it should fail; if useCache is set to true it will succeed (getting > the record from cache, even if the data is not committed to the db) > The result in #4 is wrong because T2 should not see the uncommitted record > We should never add uncommitted records to the entity cache. -- This message was sent by Atlassian JIRA (v6.3.4#6332)