Richard Zowalla created OPENJPA-3105:
----------------------------------------

             Summary: Reliable change detection for unenhanced (runtime 
subclassed) entities
                 Key: OPENJPA-3105
                 URL: https://issues.apache.org/jira/browse/OPENJPA-3105
             Project: OpenJPA
          Issue Type: Improvement
            Reporter: Richard Zowalla
             Fix For: 4.3.0


Entities that are not enhanced at build time or by the javaagent 
\(openjpa.RuntimeUnenhancedClasses=supported\) do not intercept field access. 
OpenJPA finds their changes by comparing the fields with a saved copy, and that 
comparison has several gaps. Working on OPENJPA\-3104 with adversarial review 
rounds turned up the following, each reproduced against master on Derby:* 
Primitive fields compare as always changed \(SaveFieldManager.isFieldEqual 
reads the saved value with fetchObjectField, which is null for primitives\), so 
every flush writes them. This is the cause of OPENJPA\-3104.
* The saved copy is never refreshed after a flush or commit; with the 
comparison fixed, a value changed back to an earlier value is not written.
* Rollback and savepoint rollback restore stale values; with RestoreState=none 
rolled\-back values stay in the instance and a later commit writes them; sorted 
and linked collections come back null.
* em.refresh\(\) keeps changes that were not detected yet; a datastore 
transaction does not reload an instance changed by another context; 
RetainState=false leaves collection proxies with stale change tracking 
\(duplicate element inserts\).
* merge\(\) of an unchanged detached copy rewrites element collections, 
embedded columns and the version; a copy detached by closing its EntityManager 
keeps the lazy\-load proxy of unloaded collection fields.
* Converted and externalized types without equals\(\), Serializable values 
without a value\-based equals\(\), and sets whose elements change their hash 
code are always seen as changed.
* The flush\-before\-query decision ignores pending changes of unenhanced 
instances \(a bulk UPDATE overwrites them, a SELECT misses them\).
* Changes made by flush\-time callbacks and listeners \(embedded values, 
cascaded references, element collections\) need pre\-flush handling that 
untracked instances do not get.

None of this affects enhanced entities. A snapshot\-based redesign covering all 
of the above exists on a local branch \(FieldSnapshot plus changes in 
StateManagerImpl, BrokerImpl, the attach/detach managers, HollowState, 
QueryImpl; about 600 lines plus tests\). It still found new edge cases in each 
review round, keeps serialized copies of Serializable values without equals\(\) 
\(about 5x the heap of master for large values\), and the TestUnenhanced\* 
tests are excluded from the default build. It needs a design discussion before 
it can be proposed; the recommended setup remains build\-time or javaagent 
enhancement.





--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to