Fix: @Index(columnNames) at field level is now correctly applied#149
Draft
cwegener-79 wants to merge 1 commit into
Draft
Fix: @Index(columnNames) at field level is now correctly applied#149cwegener-79 wants to merge 1 commit into
cwegener-79 wants to merge 1 commit into
Conversation
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
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