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

   https://issues.apache.org/jira/browse/OPENJPA-3104
   
   After a JPQL or native bulk DELETE removed the row of a managed, unchanged 
unenhanced (runtime-subclassed) instance, the next flush issued an UPDATE that 
hit 0 rows and failed with an `OptimisticLockException`. Found with Jakarta 
Data `deleteBy` methods in TomEE 11.
   
   Causes in the dirty check of untracked instances (`SaveFieldManager`, 
`StateManagerImpl.dirtyCheck`):
   - `isFieldEqual` read primitive fields as `null`, so every primitive field 
was always dirty.
   - A new instance has no saved values after its insert, and the fields of a 
found or queried instance are loaded after the saved copy was taken, so all 
fields compared as changed.
   - The saved values were never refreshed, so a String or Date changed back to 
an earlier value was not written.
   
   Fix:
   - `SaveFieldManager` keeps a copy of the values last loaded or written and 
compares with it (by type, arrays with `deepEquals`). Mutable values are 
copied; values that cannot be copied fall back to the previous comparison.
   - `StateManagerImpl` records the values on load and during flush; rollback, 
savepoint rollback and refresh drop them.
   - `preFlush` and `BrokerImpl.flushAdditions` run the dirty check after the 
callbacks, so changes made by `@PreUpdate` and flush listeners are written. A 
relation, embedded or externalized field changed after its owner's preFlush is 
written by the next flush, as before.
   
   Behaviour: right after a flush an unchanged unenhanced instance is no longer 
reported as dirty, as for enhanced types (`AbstractUnenhancedClassTest` 
adjusted).
   
   Not covered (OPENJPA-3105): OBJECT fields holding non-proxy collections or 
maps, Serializable values without `equals()`, values with converters or 
externalizers that cannot be copied. Rollback, refresh, merge and the flush 
decision before queries behave as before.
   
   Tests: `TestBulkDeleteOfUnenhancedType`, 40 tests: the reported scenario 
after persist, find, query, commit and in a later transaction, for field and 
property access, with `byte[]`, `@Lob` and embedded fields; changed and 
changed-back values across flushes and transactions; own and other entities' 
`@PreUpdate`, `@PostUpdate`, flush listeners and cascaded relations. 16 fail on 
master.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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