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 d7b0ade0d240b320bfc5120922e23478063d77aa
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Oct 6 15:25:19 2026 -0500

    test: give the many-to-many fixtures an owning side
    
    The domain binder now refuses a bidirectional many-to-many that neither side
    owns, so the fixtures that only needed a many-to-many (and shared one 
datastore
    boot with their siblings) declare belongsTo on one side, keeping what each 
spec
    checks. The two owner-less pairs that exist to describe the shape moved to
    grails.unbootable (NoOwnerLeft/NoOwnerRight, also read by the generator spec
    through the mapping model alone), and the pinned defect that the shape 
stored
    no rows is replaced by the startup failure spec. TableForManyCalculatorSpec
    pinned the join table names of the both-inverse binding (tag_owners for one
    side); with an owner both sides name the one table owning_side_tags.
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 .../CascadeBehaviorFetcherSpec.groovy              |  2 +-
 .../DefaultColumnNameFetcherSpec.groovy            |  1 +
 .../TableForManyCalculatorSpec.groovy              |  3 +-
 .../hibernate/HibernateToManyPropertySpec.groovy   |  1 +
 .../jpa/GrailsDomainGeneratorSpec.groovy           | 28 ++++------------
 .../jpa/ManyToManyOwnershipDefectSpec.groovy       | 39 +++-------------------
 .../secondpass/CollectionKeyBinderSpec.groovy      |  1 +
 .../secondpass/ManyToOneElementBinderSpec.groovy   |  2 ++
 .../ToManyEntityMultiTenantFilterBinderSpec.groovy |  1 +
 9 files changed, 21 insertions(+), 57 deletions(-)

diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcherSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcherSpec.groovy
index 97f5c8c3e9..1b441b50b5 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcherSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcherSpec.groovy
@@ -258,7 +258,7 @@ class Tag_BT {
     static belongsTo = Post
 }
 
-@Entity class Mammal { String name; static hasMany = [dogs: Dog] }
+@Entity class Mammal { String name; static hasMany = [dogs: Dog]; static 
belongsTo = [Dog] }
 @Entity class Dog extends Mammal { String foo; static hasMany = [animals: 
Mammal] }
 
 @Entity class Bird { String title; static belongsTo = [canary: Canary] }
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
index a7788d66be..bede05cc81 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcherSpec.groovy
@@ -145,6 +145,7 @@ class AManyToManyEntity {
 class BManyToManyEntity {
     String name
     static hasMany = [manyToMany: AManyToManyEntity]
+    static belongsTo = [AManyToManyEntity]
 }
 
 @Entity
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
index 52c7544f5e..4f9fbaabe5 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
@@ -110,7 +110,7 @@ class TableForManyCalculatorSpec extends 
HibernateGormDatastoreSpec {
         "a Map property"                      | "map_collection_owner_data"
         "a Basic property"                    | "basic_collection_owner_items"
         "an owning OneToMany"                 | "owning_side_associated_side"
-        "an owning ManyToMany"                | "tag_owners"
+        "an owning ManyToMany"                | "owning_side_tags"
         "an inverse ManyToMany"               | "owning_side_tags"
         "a ManyToMany with explicit joinTable" | "my_custom_join_table"
         "a ToMany with supportsJoinColumnMapping" | 
"unidirectional_owner_unidirectional_item"
@@ -466,6 +466,7 @@ class MapCollectionOwner {
 @Entity
 class Tag {
     static hasMany = [owners: OwningSide]
+    static belongsTo = [OwningSide]
 }
 
 @Entity
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyPropertySpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyPropertySpec.groovy
index 3153572075..4fcb32d131 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyPropertySpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyPropertySpec.groovy
@@ -710,6 +710,7 @@ class HTMPCourse {
     Long id
     String title
     static hasMany = [students: HTMPStudent]
+    static belongsTo = [HTMPStudent]
 }
 
 @Entity // Only if outside grails-app/domain
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorSpec.groovy
index dd43c06446..2afd5e7778 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorSpec.groovy
@@ -26,6 +26,8 @@ import java.lang.reflect.Field
 
 import grails.gorm.annotation.Entity
 import grails.gorm.tests.HibernateGormDatastoreSpec
+import grails.unbootable.NoOwnerLeft
+import grails.unbootable.NoOwnerRight
 import jakarta.persistence.AssociationOverride
 import jakarta.persistence.AssociationOverrides
 import jakarta.persistence.AttributeOverride
@@ -159,7 +161,7 @@ class GrailsDomainGeneratorSpec extends 
HibernateGormDatastoreSpec {
                 GenEmbedOwner, GenEmbedOther, GenEmbedBase, GenEmbedChild, 
GenEmbedFormulaOwner, GenCollSingle, GenCollKinds, GenCollLazy,
                 GenFkTarget, GenFkOwned, GenFkOwner, GenFkCascades, 
GenFkNodeA, GenFkNodeB, GenFkHasOneOwner, GenFkHasOneDetail, GenOneFace, 
GenOneNose, GenFkManyOne, GenFkOneSide, GenFkSub, GenFkSubRoot,
                 GenOmParent, GenOmChild, GenOmListed, GenOmOrdered, 
GenOmOrphan, GenOmFetched, GenOmTag, GenOmStep, GenOmKept, GenOmSortedOwner, 
GenOmMapOwner, GenMapBidiOwner, GenMapBidiChild, GenEmbAssocOwner,
-                GenMmStudent, GenMmCourse, GenMmPerson, GenMmNoOwnerA, 
GenMmNoOwnerB, GenParamsOnly, GenDecimal, GenUnversioned, GenUnversionedRoot, 
GenUnversionedChild, GenConverted)
+                GenMmStudent, GenMmCourse, GenMmPerson, GenParamsOnly, 
GenDecimal, GenUnversioned, GenUnversionedRoot, GenUnversionedChild, 
GenConverted)
     }
 
     List<StandardServiceRegistry> registries = []
@@ -1775,8 +1777,8 @@ class GrailsDomainGeneratorSpec extends 
HibernateGormDatastoreSpec {
 
     void "neither side of a many-to-many that has no belongsTo owns it, which 
the generator rejects by name"() {
         given:
-        GrailsHibernatePersistentEntity entity = entity(GenMmNoOwnerA)
-        HibernatePersistentProperty property = 
entity.getHibernatePropertyByName('others')
+        GrailsHibernatePersistentEntity entity = unbound(NoOwnerLeft, 
NoOwnerRight)
+        HibernatePersistentProperty property = 
entity.getHibernatePropertyByName('rights')
 
         expect:
         !newGenerator().supports(property)
@@ -1858,10 +1860,10 @@ class GrailsDomainGeneratorSpec extends 
HibernateGormDatastoreSpec {
         return newGenerator().generateAll(domainClasses.collect { entity(it) 
}, getClass().classLoader)
     }
 
-    private GrailsHibernatePersistentEntity unbound(Class<?> domainClass) {
+    private GrailsHibernatePersistentEntity unbound(Class<?> domainClass, 
Class<?>... companions) {
         // the mapping model alone, so a domain the binder cannot boot can 
still be described
         return (GrailsHibernatePersistentEntity) new HibernateMappingContext(
-                new HibernateConnectionSourceSettings(), (Object) null, 
[domainClass] as Class[]).getPersistentEntity(domainClass.name)
+                new HibernateConnectionSourceSettings(), (Object) null, 
([domainClass] + companions.toList()) as 
Class[]).getPersistentEntity(domainClass.name)
     }
 
     private Map<String, Column> overrides(Class<?> owner, String embedded) {
@@ -3079,22 +3081,6 @@ class GenMmPerson {
     static hasMany = [friends: GenMmPerson]
 }
 
-@Entity
-class GenMmNoOwnerA {
-
-    Set<GenMmNoOwnerB> others
-
-    static hasMany = [others: GenMmNoOwnerB]
-}
-
-@Entity
-class GenMmNoOwnerB {
-
-    Set<GenMmNoOwnerA> others
-
-    static hasMany = [others: GenMmNoOwnerA]
-}
-
 @Entity
 class GenMmSelf {
 
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/ManyToManyOwnershipDefectSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/ManyToManyOwnershipDefectSpec.groovy
index 1eddb13fa9..c46b3128c1 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/ManyToManyOwnershipDefectSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/ManyToManyOwnershipDefectSpec.groovy
@@ -23,14 +23,15 @@ import grails.gorm.tests.HibernateGormDatastoreSpec
 import spock.lang.PendingFeature
 
 /**
- * Pins two defects of the domain binder in the many-to-many ownership rules, 
found by comparing it with the annotations
- * {@link GrailsDomainGenerator} generates. The generator does not copy 
either: it rejects the second shape by name and
- * follows the owning side for the first. Each feature reports as fixed when 
the binder is.
+ * Pins a defect of the domain binder in the many-to-many ownership rules, 
found by comparing it with the annotations
+ * {@link GrailsDomainGenerator} generates. The generator does not copy it: it 
follows the owning side. The feature reports
+ * as fixed when the binder is. A many-to-many that neither side owns, the 
other defect found that way, no longer boots: see
+ * {@code ManyToManyWithoutOwnerSpec}.
  */
 class ManyToManyOwnershipDefectSpec extends HibernateGormDatastoreSpec {
 
     void setupSpec() {
-        manager.registerDomainClasses(DefectNamedOwner, DefectNamedInverse, 
DefectLeft, DefectRight)
+        manager.registerDomainClasses(DefectNamedOwner, DefectNamedInverse)
     }
 
     @PendingFeature(reason = 'the inverse side names its join table from its 
own mapping, not from the owner that names it, so it reads another table')
@@ -45,18 +46,6 @@ class ManyToManyOwnershipDefectSpec extends 
HibernateGormDatastoreSpec {
         expect:
         DefectNamedInverse.get(inverse.id).owners*.name == ['owner']
     }
-
-    @PendingFeature(reason = 'with no belongsTo neither side owns the 
many-to-many, so the binder binds both collections inverse and writes no row')
-    void "a many-to-many with no belongsTo on either side persists its rows"() 
{
-        given:
-        DefectLeft left = new DefectLeft(name: 'left')
-        left.addToRights(new DefectRight(name: 'right'))
-        left.save(flush: true, failOnError: true)
-        session.clear()
-
-        expect:
-        DefectLeft.get(left.id).rights*.name == ['right']
-    }
 }
 
 @Entity
@@ -81,21 +70,3 @@ class DefectNamedInverse {
     static hasMany = [owners: DefectNamedOwner]
     static belongsTo = [owners: DefectNamedOwner]
 }
-
-@Entity
-class DefectLeft {
-
-    String name
-    Set<DefectRight> rights
-
-    static hasMany = [rights: DefectRight]
-}
-
-@Entity
-class DefectRight {
-
-    String name
-    Set<DefectLeft> lefts
-
-    static hasMany = [lefts: DefectLeft]
-}
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
index 902da54354..8c268b0ff1 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyBinderSpec.groovy
@@ -242,6 +242,7 @@ class CKBManyToManyOwner {
 class CKBManyToManyItem {
     Long id
     static hasMany = [owners: CKBManyToManyOwner]
+    static belongsTo = [CKBManyToManyOwner]
 }
 
 @Entity
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToOneElementBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToOneElementBinderSpec.groovy
index 6bc267ca95..2c9aa59b17 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToOneElementBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ManyToOneElementBinderSpec.groovy
@@ -90,6 +90,7 @@ class MTMEItem {
     Long id
     String description
     static hasMany = [owners: MTMEOwner]
+    static belongsTo = [MTMEOwner]
 }
 
 @Entity
@@ -101,4 +102,5 @@ class MTMEBase {
 @Entity
 class MTMESubtype extends MTMEBase {
     static hasMany = [related: MTMEBase]
+    static belongsTo = [MTMEBase]
 }
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ToManyEntityMultiTenantFilterBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ToManyEntityMultiTenantFilterBinderSpec.groovy
index 9a5fc4254e..cb442bcc37 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ToManyEntityMultiTenantFilterBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ToManyEntityMultiTenantFilterBinderSpec.groovy
@@ -187,4 +187,5 @@ class CMTBManyToManyItem implements 
MultiTenant<CMTBManyToManyItem> {
     Long id
     Long tenantId
     static hasMany = [owners: CMTBManyToManyOwner]
+    static belongsTo = [CMTBManyToManyOwner]
 }

Reply via email to