[OPENJPA-3002] Fix: @Index(columnNames) at field level is now correctly applied - #149
Merged
Conversation
cwegener-79
marked this pull request as ready for review
May 26, 2026 08:35
Contributor
Author
|
Just a quick nudge on this PR 🙂 |
solomax
requested changes
Jun 3, 2026
solomax
left a comment
Contributor
There was a problem hiding this comment.
Could you please remove all whitespaces-only changes to AnnotationPersistenceMappingParser
Thanks in advance :)
cwegener-79
force-pushed
the
master
branch
2 times, most recently
from
June 3, 2026 07:25
6851bcf to
aa5e4b3
Compare
Contributor
|
@cwegener-79 could you please rebase this one? we just have merged huge new functionality (this is why merging was delayed) |
The columnNames attribute of the OpenJPA-specific @Index annotation was not passed to the internal parseIndex overload and therefore silently ignored. A new overload parseIndex(..., String[] columnNames) adds the specified columns to the schema Index object. The existing 4-parameter method delegates to it in a backwards-compatible way. Regression test: TestIndexColumnNames with EntityWithIndexColumnNames
- Replace fully qualified org.apache.openjpa.jdbc.schema.Column with the already-imported short name Column - Add missing braces around the for-loop body
Contributor
Author
No Problem, I've just rebased it. |
Contributor
|
Thanks for the contribution! |
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.
Fix:
@Index(columnNames)at field level is silently ignoredProblem
The OpenJPA-specific
@Indexannotation (org.apache.openjpa.persistence.jdbc.Index) supports acolumnNamesattribute that allows explicitly defining which columns should be included in a database index when the annotation is placed on a field or method. However, these column names were silently ignored during annotation parsing.Root cause:
AnnotationPersistenceMappingParser.parseIndex(MappingInfo, Index)called an internal overload passing onlyname,enabled, andunique—idx.columnNames()was never forwarded:As a result, any entity using
@Index(columnNames = {"COL_A", "COL_B"})at the field level would get a schema index with no explicitly defined columns.Fix
parseIndex(MappingInfo, Index)now passesidx.columnNames()to a new overload.parseIndex(MappingInfo, String, boolean, boolean, String[])createsColumnobjects from the provided names and adds them to theIndexschema object.protected4-parameter overload delegates to the new method withnullcolumn names, preserving backwards compatibility for subclasses.Testing
Added a regression test that verifies the fix end-to-end:
EntityWithIndexColumnNames— test entity with@Index(name="idx_col_a_b", columnNames={"COL_A","COL_B"})on a field.TestIndexColumnNames#testFieldIndexColumnNamesAreApplied— asserts that after full mapping resolution the schema index contains both explicitly named columns. The test fails without the fix (getColumns().length == 0) and passes with it.Changed Files
AnnotationPersistenceMappingParser.javaEntityWithIndexColumnNames.javaTestIndexColumnNames.java