This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 9.0.x-h7-improvement-phase3
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 97c02f121e7a4cf3ec0ae8c0b4839665a6e1c38a
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Oct 6 15:25:53 2026 -0500

    docs: a many-to-many needs belongsTo on one side or the application fails 
at startup
    
    Documents the 9.0 behaviour in the many-to-many guide page and adds a row 
to the
    Hibernate 7 migration checklist, the place the 9.0 upgrade notes live 
(grails-doc
    has no 9.0 upgrade page yet).
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 .../src/docs/asciidoc/domainClasses/gormAssociation/manyToMany.adoc   | 2 ++
 .../docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc      | 4 ++++
 2 files changed, 6 insertions(+)

diff --git 
a/grails-data-hibernate7/docs/src/docs/asciidoc/domainClasses/gormAssociation/manyToMany.adoc
 
b/grails-data-hibernate7/docs/src/docs/asciidoc/domainClasses/gormAssociation/manyToMany.adoc
index bf4badfaa9..0796424eae 100644
--- 
a/grails-data-hibernate7/docs/src/docs/asciidoc/domainClasses/gormAssociation/manyToMany.adoc
+++ 
b/grails-data-hibernate7/docs/src/docs/asciidoc/domainClasses/gormAssociation/manyToMany.adoc
@@ -21,6 +21,8 @@ under the License.
 
 A many-to-many association is created when both domain classes declare 
`hasMany` pointing at each other, and one side also declares `belongsTo`.
 
+NOTE: One side of a bidirectional many-to-many must declare `belongsTo`: the 
owning side is the one that writes the join table rows. If neither side 
declares it, the relationship would never be stored, so the application fails 
at startup with a `MappingException` that names both sides, for example 
`Neither side of the many-to-many between [Author.books] and [Book.authors] 
declares belongsTo, so the relationship would never be stored`. Declare 
`belongsTo` on the side that should be owned  [...]
+
 === Declaring the Relationship
 
 [source,groovy]
diff --git 
a/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
 
b/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
index 4df1abb19f..15bd28e7c7 100644
--- 
a/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
+++ 
b/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
@@ -105,6 +105,10 @@ If you are migrating an application from Hibernate 5 or 
the Grails Hibernate 5 p
 | Hibernate 7 is less tolerant of inconsistent managed association state at 
flush time.
 | Keep both sides of bidirectional associations synchronized. Prefer GORM 
association helpers where possible.
 
+| Many-to-many without `belongsTo`
+| Grails 9 refuses to start when a bidirectional many-to-many has no 
`belongsTo` on either side. Earlier versions bound both sides as inverse, so no 
join table row was ever written and the relationship was silently lost.
+| Declare `belongsTo` on the side that should be owned, for example `static 
belongsTo = Author` in `Book`. For a many-to-many from a class to itself, 
`belongsTo` names the class itself. The startup error names both sides of each 
affected relationship. See <<gormAssociation-manyToMany,Many-to-Many 
Associations>>.
+
 | Query locks and query cache
 | Locked queries are not query-cacheable.
 | Do not expect `lock: true` queries to use the query cache. Treat 
pessimistically locked queries as database reads that require fresh row state.

Reply via email to