Skip to content

[OPENJPA-3106] Compare a value of a non-deterministic converter by equals - #336

Open
rzo1 wants to merge 4 commits into
masterfrom
OPENJPA-3106
Open

rzo1 wants to merge 4 commits into
masterfrom
OPENJPA-3106

Conversation

@rzo1

@rzo1 rzo1 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/OPENJPA-3106

An AttributeConverter that returns a different column value for the same attribute on each call (e.g. encryption with a random salt or IV) made an attribute converted as a whole (a collection, a map or an object) dirty at every flush. An unchanged instance was updated each time, and after a JPQL bulk or native DELETE removed its row the next flush failed with an OptimisticLockException. This affected enhanced entities too.

Cause: the OPENJPA-3019 check compares the column value saved at load or flush with a fresh convertToDatabaseColumn() of the current attribute.

Fix (StateManagerImpl.isWholeConvertedChanged, used by the flush check, merge, the data cache and the rollback restore):

  • Equal column values: unchanged, as before. Deterministic converters stop here and cost the same as before.
  • Different column values: the attribute is converted again. If both conversions agree, the field changed (OPENJPA-3019 behaviour). If they disagree, the saved column value is converted back and compared with the attribute by equals(), as Hibernate does.

Behaviour change: a change made in place to state that equals() of the attribute type (or of its elements) does not cover is no longer written for such converters. openjpa.Compatibility=CompareConvertedValuesByEquals=false writes these attributes at every flush as before. Documented in the 4.3.0 migration considerations and the upgrade notes.

Not covered: a type without equals() behind such a converter is still written at every flush.

Tests: TestNonDeterministicConverter (13), TestNonDeterministicConverterDataCache (1), TestNonDeterministicObjectConverterEquals (6, default) and TestNonDeterministicObjectConverter (3, option off). The OPENJPA-3019 tests (TestConvertedInPlaceChange) and all TestConverted* pass.

…uals

A converter that converts the same value differently on each call made
an attribute converted as a whole dirty at every flush. Compare it with
the value converted back from the saved column value instead.
CompareConvertedValuesByEquals=false restores the previous behaviour.

Generated-by: Claude Code (Opus 5.5)
rzo1 added 2 commits December 2, 2026 13:21
# Conflicts:
#	openjpa-project/src/docs/asciidoc/migration_considerations.adoc
@rzo1
rzo1 marked this pull request as ready for review December 4, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants