Skip to content

[OPENJPA-2973] Consult the AttributeConverter for null values - #201

Merged
cristof merged 1 commit into
masterfrom
OPENJPA-2973
Oct 6, 2026
Merged

cristof merged 1 commit into
masterfrom
OPENJPA-2973

Conversation

@rzo1

@rzo1 rzo1 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

As required by Jakarta Persistence 3.2 an AttributeConverter is now consulted for null in both directions; previously a null attribute or a null column value bypassed it, so a converter mapping null to a column default was never applied. Queries are deliberately unaffected: a null in a query still means SQL NULL and is never passed through the converter, so IS NULL and null parameters keep their previous meaning. Converter implementations must therefore be null-safe — the bundled test converters were not and are fixed — and the migration guide documents both the requirement and the change in stored data; the CDI and direct-cast questions from the review are answered in comments, since the kernel has neither a container hook nor the jakarta.persistence dependency.

A converter may legitimately map null to a column or attribute default,
so drop the val == null short-circuits in the externalization path. A
null returned by the converter still stores/reads a null column value.

Collection and map fields keep converting their elements through
ConverterElementHandler, so the new guard mirrors isExternalized().
Arrays stay on the whole-value path, matching the same collection/map
test that MappingRepository applies before its array handling.

Queries are left alone: a null in a query means SQL NULL and is not
passed through the converter, so "x IS NULL", "x = :nullParam",
"SET x = NULL" and "SET x = :nullParam" keep one meaning between them.

A RuntimeException from a converter is still wrapped in a StoreException,
but with the localized converter-err message, so the failure names the
field and the offending value instead of only the converter's own text.

Document why the converter is invoked reflectively (openjpa-kernel does
not depend on jakarta.persistence-api) and that there is no container
hook for CDI-managed converters, and note the incompatibility in the
4.2.0 migration considerations.

The test converters are made null-safe, as the specification requires of
a converter, and the null shapes they cover - an array attribute with an
auto-applied converter, a converted attribute of an embeddable and an
absent embeddable - are pinned by tests.
@rzo1 rzo1 self-assigned this Oct 5, 2026
@rzo1
rzo1 requested review from cristof and solomax October 5, 2026 19:06
@cristof
cristof merged commit b4bfa57 into master Oct 6, 2026
9 of 12 checks passed
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.

3 participants