[ 
https://issues.apache.org/jira/browse/OPENJPA-3002?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Maxim Solodovnik resolved OPENJPA-3002.
---------------------------------------
      Assignee: Maxim Solodovnik
    Resolution: Fixed

> 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
>            Assignee: 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