cwegener-79 opened a new pull request, #149:
URL: https://github.com/apache/openjpa/pull/149

   ## 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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to