[OPENJPA-2967] Make VERSION() work for surrogate versions - #168
Open
rzo1 wants to merge 1 commit into
Open
Conversation
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.
cristof
approved these changes
Aug 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note that the issue description is out of date:
getColumns()no longer callsgetVersionFieldMapping()andinitialize()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@Versionfield.initialize()admits such a type on purpose, since its version columns exist, so the null escaped intoJPQLExpressionBuilder(type.isPrimitive()forSELECT VERSION(e)) and intoFilters.wrap(forWHERE VERSION(e) = :v), both failing with a NullPointerException.getType()now falls back toObject.class— the same answer the in-memoryVersionValalready gives, so the two query paths agree — andtoDataStoreValue()converts through the version column's java type. Types with a real@Versionfield are unaffected.initialize()also reported an invalidVERSION()argument with thebad-getobjectidmessage, 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.