[
https://issues.apache.org/jira/browse/OPENJPA-2973?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18123515#comment-18123515
]
ASF subversion and git services commented on OPENJPA-2973:
----------------------------------------------------------
Commit 79ad92094e16fa033179bc88aa090859b285659a in openjpa's branch
refs/heads/OPENJPA-2973 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=79ad92094 ]
[OPENJPA-2973] Consult the AttributeConverter for null values
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.
> Converter instantiated reflectively, skips CDI and nulls
> --------------------------------------------------------
>
> Key: OPENJPA-2973
> URL: https://issues.apache.org/jira/browse/OPENJPA-2973
> Project: OpenJPA
> Issue Type: Sub-task
> Components: jpa
> Affects Versions: 4.2.0
> Reporter: Maxim Solodovnik
> Priority: Major
> Fix For: 4.2.0
>
>
> Discussion thread:
> https://github.com/apache/openjpa/pull/144#discussion_r3683003654
> **(low)** Two questions: (1) the converter is instantiated via
> `getDeclaredConstructor().newInstance()`, bypassing CDI-managed converters
> (JPA allows converters as CDI beans with injection); (2) why
> reflection/`findMethod` instead of casting to
> `jakarta.persistence.AttributeConverter` and calling it directly? Note also
> the `val == null` short-circuits mean a converter mapping null to a default
> value is never consulted for nulls.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)