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

   ## Problem
   When neither side of a many-to-many declares `belongsTo`, both collections 
were bound inverse and nothing is ever written to a join table: the 
relationship is silently lost. Reproduced on Hibernate 5 as well (identical 
data loss). The guide and the H7 docs both say one side must declare 
`belongsTo`.
   
   ## Fix
   `HibernateManyToManyProperty.isOwningSide()` now chooses one owner when 
neither side has `belongsTo`: the entity whose name sorts first, then the 
property name. Both sides apply the same rule, so exactly one owns and both 
resolve the same join table. `belongsTo` still wins when present. Cascade 
defaults are unchanged.
   
   ## Behaviour change to review
   Failing at startup was tried first; it broke 14 existing H7 specs whose 
fixtures use this shape, so the deterministic owner was chosen instead. 
Existing apps with this shape go from two unused join tables to one used table 
named after the chosen owner. The choice is alphabetical: arbitrary but stable. 
A many-to-many from an entity to itself (`mappedBy` its own property) already 
fails with a duplicated column with and without this change and is out of 
scope. `manyToMany.adoc` notes the rule. The expected name in one 
`TableForManyCalculatorSpec` row changes (`tag_owners` to `owning_side_tags`) 
because that fixture has no `belongsTo` and the old value encoded the bug.
   
   ## Tests
   New `ManyToManyWithoutOwnerSpec` (persist through one side, reload; failed 
before), rows in `HibernateManyToManyPropertySpec`. `grails.gorm.*` and 
`org.grails.orm.hibernate.*`: 3036 tests, 0 failures after the two spec updates 
described above.
   
   🤖 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