Skip to content

[OPENJPA-2974] Convert String cache mode properties to their enum again - #174

Open
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2974
Open

[OPENJPA-2974] Convert String cache mode properties to their enum again#174
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2974

Conversation

@rzo1

@rzo1 rzo1 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

convertToKernelValue() returned a String value for cache.retrieveMode and cache.storeMode untouched. Since this PR the bean property for those keys resolves to the new JPA 3.2 setters on EntityManagerImpl, which take the jakarta enums, so em.setProperty("jakarta.persistence.cache.retrieveMode", "USE") reached Method.invoke with a String and died with an argument type mismatch. The same applies to the map passed to createEntityManager(), so this affects ordinary configuration, not only the new API.

The conversion is now driven by the target type rather than by the key: a value already of the target type passes through, a String is parsed into the target enum, and an enum of a different type is mapped by constant name — which is what lets a jakarta CacheStoreMode reach a kernel DataCacheStoreMode. An unusable String now fails with a message naming the property and its legal values. The early return this replaces cannot simply be dropped: it was added together with those setters and is what keeps the enum-valued form working.

Being type-driven, it also fixes jakarta.persistence.lock.scope="EXTENDED", which failed in StringUtil.parse with "Unsupported type".

A null mode now resets the fetch plan to its default rather than meaning BYPASS, so clearing one of these properties does not leave the plan bypassing the cache; both setters document that.

convertToKernelValue() returned a String value for cache.retrieveMode and
cache.storeMode untouched. Since PR #144 the bean property for those keys
resolves to the new JPA 3.2 setters on EntityManagerImpl, which take the
jakarta enums, so em.setProperty("jakarta.persistence.cache.retrieveMode",
"USE") reached Method.invoke with a String and died with an argument type
mismatch. The same applies to the map passed to createEntityManager().

The conversion is now driven by the target type rather than by the key: a
value already of the target type passes through, a String is parsed into
the target enum, and an enum of a different type is mapped by constant
name, which is what lets a jakarta CacheStoreMode reach a kernel
DataCacheStoreMode. An unusable String now fails with a message naming the
property and its legal values instead of an argument type mismatch. The
early return this replaces cannot simply be dropped: it was added with
those setters and is what keeps the enum-valued form working.

Being type-driven, it also fixes jakarta.persistence.lock.scope="EXTENDED",
which failed in StringUtil.parse with "Unsupported type".

A null mode now resets the fetch plan to its default rather than meaning
BYPASS, so clearing one of these properties does not leave the plan
bypassing the cache; both setters document that.
@rzo1 rzo1 self-assigned this Sep 2, 2026
@rzo1
rzo1 requested review from cristof and solomax September 2, 2026 18:08
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