Skip to content

[OPENJPA-2984] Record why an id class is no longer checked for Serializable - #176

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

[OPENJPA-2984] Record why an id class is no longer checked for Serializable#176
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2984

Conversation

@rzo1

@rzo1 rzo1 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

To answer the review question: the check was not lost in the rewrite, and the warning should not come back.

Jakarta Persistence 3.2 section 2.4.1 dropped both the public and the Serializable requirement for a primary key class — the release notes say so verbatim — and bf3d2b1 removed the warning deliberately: the same commit deleted the id-class-not-serializable message key, relaxed the matching public-ness rules in the kernel (getConstructorgetDeclaredConstructor, setAccessible), and added TestNonPublicIdClass with a package-private, non-serializable id class. Restoring the warning would fire against metadata the specification allows, including that test's own entity, and against 29 of the 67 @IdClass targets in our test sources.

What was missing is the reason, so both parsers now carry it where the check used to be, along with the consequence that does survive: a non-serializable id class cannot be used where OpenJPA serializes the identity object wrapping it — serializing a detached entity, remote commit events, a distributed data cache — which fails with a NotSerializableException naming the class.

The manual still listed the pre-3.2 rules, so the identity class criteria are corrected. Note the constructor requirement is only that a no-args one exists, of any visibility, since validateAppIdClassMethods uses getDeclaredConstructor(); a record has none, so a record @IdClass is rejected.

No behaviour change. TestNonPublicIdClass already pins the relaxation and would fail if anyone reinstated a hard check.

…izable

The check was not lost in the rewrite. Jakarta Persistence 3.2 section
2.4.1 dropped both the public and the Serializable requirement for a
primary key class, and bf3d2b1 removed the warning deliberately: the same
commit deleted the message key, relaxed the matching public-ness rules in
the kernel and added a test with a package private, non-serializable id
class. Restoring the warning would fire against metadata the specification
allows, including that test's own entity.

What was missing is the reason, so both parsers now carry it where the
check used to be, along with the consequence that does survive: a
non-serializable id class cannot be used where OpenJPA serializes the
identity object it wraps, which detached entities, remote commit events and
a distributed data cache do.

The manual still listed the pre-3.2 rules; its identity class criteria are
corrected. Note that the constructor requirement is only that one without
arguments exists, of any visibility, since validateAppIdClassMethods uses
getDeclaredConstructor().
@rzo1 rzo1 self-assigned this Sep 2, 2026
@rzo1
rzo1 requested review from cristof and solomax September 2, 2026 19:18
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