Skip to content

[OPENJPA-2967] Make VERSION() work for surrogate versions - #168

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

[OPENJPA-2967] Make VERSION() work for surrogate versions#168
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2967

Conversation

@rzo1

@rzo1 rzo1 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Note that the issue description is out of date: getColumns() no longer calls getVersionFieldMapping() and initialize() already validates the class mapping, both since e94a851, and both are already covered by tests. What remains is the surrogate case.

VersionVal.getType() returned null for a type whose version is mapped by the version strategy rather than by a @Version field. initialize() admits such a type on purpose, since its version columns exist, so the null escaped into JPQLExpressionBuilder (type.isPrimitive() for SELECT VERSION(e)) and into Filters.wrap (for WHERE VERSION(e) = :v), both failing with a NullPointerException.

getType() now falls back to Object.class — the same answer the in-memory VersionVal already gives, so the two query paths agree — and toDataStoreValue() converts through the version column's java type. Types with a real @Version field are unaffected.

initialize() also reported an invalid VERSION() argument with the bad-getobjectid message, which describes an object id failure and whose argument is null for a bare identification variable. It now uses a dedicated message naming the path.

VersionVal.getType() returned null for a type whose version is mapped by
the version strategy rather than by a @Version field. initialize() admits
such a type on purpose, since its version columns exist, so the null
escaped into JPQLExpressionBuilder (type.isPrimitive() for SELECT
VERSION(e)) and into Filters.wrap (for WHERE VERSION(e) = :v), both of
which failed with a NullPointerException. getType() now falls back to
Object.class, the same answer the in-memory VersionVal gives, and
toDataStoreValue() converts through the version column's java type.

initialize() also reported an invalid VERSION() argument with the
bad-getobjectid message, which describes an object id failure and whose
argument is null for a bare identification variable. It now uses a
dedicated message naming the path.

Known limitations, each worth its own issue: a multi-column surrogate
version still compares and loads through the first column only, and a
subclass of a versioned entity is rejected because SuperclassVersionStrategy
maps no columns of its own.
@rzo1
rzo1 requested review from cristof and solomax August 29, 2026 17:53
@rzo1 rzo1 self-assigned this Aug 29, 2026
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