[ 
https://issues.apache.org/jira/browse/OPENJPA-3002?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18106461#comment-18106461
 ] 

ASF subversion and git services commented on OPENJPA-3002:
----------------------------------------------------------

Commit 2d865d891145e86516f5b7a1f22d8f8effa44eb5 in openjpa's branch 
refs/heads/master from cwegener-79
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=2d865d891 ]

[OPENJPA-3002] Fix: @Index(columnNames) at field level is now correctly applied 
(#149)

* Fix: @Index(columnNames) at field level is now correctly applied

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

* Refactor: improve readability in parseIndex()

- Replace fully qualified org.apache.openjpa.jdbc.schema.Column with
  the already-imported short name Column
- Add missing braces around the for-loop body

* Cleanup: remove spurious whitespace changes from parseIndex()

> Column names specified at @Index annotation silently ignored
> ------------------------------------------------------------
>
>                 Key: OPENJPA-3002
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-3002
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 4.1.1
>            Reporter: Maxim Solodovnik
>            Priority: Major
>             Fix For: 4.2.0
>
>
> ## Fix: `@Index(columnNames)` at field level is silently ignored
> ### Problem
> The OpenJPA-specific `@Index` annotation 
> (`org.apache.openjpa.persistence.jdbc.Index`) supports a `columnNames` 
> attribute 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 only `name`, `enabled`, and 
> `unique` — `idx.columnNames()` was never forwarded:
> ```java
> // Before — columnNames dropped on the floor:
> private void parseIndex(MappingInfo info, Index idx) {
>     parseIndex(info, idx.name(), idx.enabled(), idx.unique());
> }
> ```
> 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 passes `idx.columnNames()` to a new 
> overload.
> - New method `parseIndex(MappingInfo, String, boolean, boolean, String[])` 
> creates `Column` objects from the provided names and adds them to the `Index` 
> schema object.
> - The existing `protected` 4-parameter overload delegates to the new method 
> with `null` column 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
> | File | Change |
> |---|---|
> | `AnnotationPersistenceMappingParser.java` | Bug fix + 
> whitespace/indentation cleanup |
> | `EntityWithIndexColumnNames.java` | New test entity |
> | `TestIndexColumnNames.java` | New regression test |



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to