borinquenkid opened a new pull request, #16539:
URL: https://github.com/apache/grails-core/pull/16539

   ## Problem
   For a foreign key into an entity whose composite identifier contains a 
to-one to **another composite entity** (a nested composite chain), the 
generated foreign key columns are named in the nested entity's *mapped* order, 
while Hibernate sorts the nested component's properties by name and gives the 
referenced key's columns that order. The types follow positionally, so names 
and types are swapped relative to each other. Example (`Leaf` -> `Middle` -> 
`GrandParent`, where `GrandParent` has `composite('name', 'luckyNumber')`, a 
String and an Integer):
   
   | column of `leaf` | type before | type after |
   |---|---|---|
   | `cfk_middle_grand_parent_name` | `INTEGER` | `VARCHAR` |
   | `cfk_middle_grand_parent_lucky_number` | `VARCHAR` | `INTEGER` |
   
   It does **not** occur with a single level (a child pointing at a composite 
parent), where `sortOrIndexForeignKeyColumns` already aligns the columns.
   
   ## Impact
   Cosmetic. Positionally the columns still line up with the primary key, so 
save and reload work (verified through the GORM API before and after). The 
wrong names and types are visible to schema diff tools, 
`hibernate.hbm2ddl.auto=validate` and native SQL.
   
   ## Fix
   `CompositeIdentifierToManyToOneBinder.tryExpandNestedComposite` now sorts 
the nested parts by property name when expanding, matching Hibernate's order.
   
   ## Tests
   New `CompositeForeignKeyColumnTypesSpec` (4 features): the one-level DDL, 
the three-level DDL (fails before the fix), and runtime save/reload for both. 
`CompositeIdentifierToManyToOneBinderSpec`'s nested mock now declares its parts 
in reverse name order so it pins the sorting. `cfg.*`, `grails.gorm.tests.*` 
and `*Composite*`: 1930 tests, 0 failures, 3 skipped.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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