Repository navigation
[OPENJPA-3104] Do not update an unchanged unenhanced instance on flush - #335
Merged
Merged
Conversation
Compare untracked fields with the values last loaded or written, read primitives by type, and detect changes made by flush callbacks. Generated-by: Claude Code (Opus 5.5)
rzo1
marked this pull request as ready for review
December 2, 2026 10:14
…nced classes Generated-by: Claude Code (Opus 5.5)
…e DELETE test Generated-by: Claude Code (Opus 5.5)
cristof
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 DatadeleteBymethods in TomEE 11.Causes in the dirty check of untracked instances (
SaveFieldManager,StateManagerImpl.dirtyCheck):isFieldEqualread primitive fields asnull, so every primitive field was always dirty.Fix:
SaveFieldManagerkeeps a copy of the values last loaded or written and compares with it (by type, arrays withdeepEquals). Mutable values are copied; values that cannot be copied fall back to the previous comparison.StateManagerImplrecords the values on load and during flush; rollback, savepoint rollback and refresh drop them.preFlushandBrokerImpl.flushAdditionsrun the dirty check after the callbacks, so changes made by@PreUpdateand 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 (
AbstractUnenhancedClassTestadjusted).Not covered (OPENJPA-3105, closed as Won't Fix; the gaps are now listed in the Runtime Unenhanced Classes section of the reference guide): 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, withbyte[],@Loband 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.