You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/10/22 16:39:32 UTC

(grails-core) 01/02: test(hibernate7): keep the 9.x refusal of an ownerless many-to-many over the 8.x warning spec

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 e7b263b07cf0861119ac113a215f1aa56543fdb3
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Thu Oct 22 11:21:51 2026 -0500

    test(hibernate7): keep the 9.x refusal of an ownerless many-to-many over the 8.x warning spec
    
    The 10.0.x merge brought ManyToManyWithoutOwnerWarningSpec, which expects
    the Grails 8 behaviour: a bidirectional many-to-many with no belongsTo on
    either side binds, and the binder logs one warning. On this branch such a
    mapping refuses to start with a MappingException that names both sides
    (ManyToManyOwnerValidator, documented in manyToMany.adoc and
    hibernateVersions.adoc, covered by ManyToManyWithoutOwnerSpec including the
    circular and the Map-sided cases), so the warning spec cannot pass and its
    cases are already covered. The spec goes; its Warn* fixtures went with it,
    so the classic oracle no longer expects them.
    
    The oracle also drops the record of SingleTableSubClassDefault, whose
    classic fixture left with the classic binder in the same merge.
---
 .../tests/ManyToManyWithoutOwnerWarningSpec.groovy | 307 ---------------------
 .../resources/classic-oracle/ddl-differential.txt  |   4 -
 .../classic-oracle/generator-differential.txt      |   4 -
 3 files changed, 315 deletions(-)

diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/ManyToManyWithoutOwnerWarningSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/ManyToManyWithoutOwnerWarningSpec.groovy
deleted file mode 100644
index ad9aedcdcd..0000000000
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/ManyToManyWithoutOwnerWarningSpec.groovy
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    https://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package grails.gorm.tests
-
-import spock.lang.Specification
-
-import grails.gorm.annotation.Entity
-import org.grails.orm.hibernate.HibernateDatastore
-
-/**
- * A many-to-many where neither side declares {@code belongsTo} has no owning side, so the relationship is never
- * stored. A warning at startup points this out.
- */
-class ManyToManyWithoutOwnerWarningSpec extends Specification {
-
-    private static final String WARNING = 'declares belongsTo, so the relationship is not stored'
-
-    void 'a many-to-many with no belongsTo on either side logs one warning'() {
-        when:
-        var output = stderrWhile {
-            new HibernateDatastore(WarnNoOwnerLeft, WarnNoOwnerRight).close()
-        }
-
-        then:
-        output.readLines().count { it.contains(WARNING) } == 1
-        output.contains('[grails.gorm.tests.WarnNoOwnerLeft.rights] and [grails.gorm.tests.WarnNoOwnerRight.lefts]')
-        output.contains('for example in WarnNoOwnerRight: static belongsTo = WarnNoOwnerLeft')
-    }
-
-    void 'a many-to-many with belongsTo on one side logs no warning'() {
-        when:
-        var output = stderrWhile {
-            new HibernateDatastore(WarnOwnedLeft, WarnOwnerRight).close()
-        }
-
-        then:
-        !output.contains(WARNING)
-    }
-
-    void 'a unidirectional self-referencing one-to-many logs no warning'() {
-        when:
-        var output = stderrWhile {
-            new HibernateDatastore(WarnSelfReferencing).close()
-        }
-
-        then:
-        !output.contains(WARNING)
-    }
-
-    void 'a circular many-to-many with no belongsTo logs one warning, because nothing is stored'() {
-        given:
-        var output = null
-        HibernateDatastore datastore = null
-
-        when:
-        output = stderrWhile {
-            datastore = new HibernateDatastore(WarnCircular)
-        }
-        WarnCircular.withNewTransaction {
-            WarnCircular followed = new WarnCircular(name: 'followed').save(failOnError: true)
-            WarnCircular follower = new WarnCircular(name: 'follower').save(failOnError: true)
-            follower.addToFollowing(followed)
-            follower.save(failOnError: true)
-        }
-
-        then:
-        output.readLines().count { it.contains(WARNING) } == 1
-        output.contains('[grails.gorm.tests.WarnCircular.followers] and [grails.gorm.tests.WarnCircular.following]')
-        output.contains('for example in WarnCircular: static belongsTo = WarnCircular')
-        WarnCircular.withNewSession {
-            WarnCircular.findByName('follower').following.isEmpty() &&
-                    WarnCircular.findByName('followed').followers.isEmpty()
-        }
-
-        cleanup:
-        datastore?.close()
-    }
-
-    void 'a circular many-to-many with belongsTo logs no warning and stores the relationship'() {
-        given:
-        var output = null
-        HibernateDatastore datastore = null
-
-        when:
-        output = stderrWhile {
-            datastore = new HibernateDatastore(WarnCircularOwned)
-        }
-        WarnCircularOwned.withNewTransaction {
-            WarnCircularOwned followed = new WarnCircularOwned(name: 'followed').save(failOnError: true)
-            WarnCircularOwned follower = new WarnCircularOwned(name: 'follower').save(failOnError: true)
-            follower.addToFollowing(followed)
-            follower.save(failOnError: true)
-        }
-
-        then:
-        !output.contains(WARNING)
-        WarnCircularOwned.withNewSession {
-            WarnCircularOwned.findByName('follower').following*.name == ['followed'] &&
-                    WarnCircularOwned.findByName('followed').followers*.name == ['follower']
-        }
-
-        cleanup:
-        datastore?.close()
-    }
-
-    void 'a unidirectional one-to-many and a basic collection log no warning'() {
-        when:
-        var output = stderrWhile {
-            new HibernateDatastore(WarnParent, WarnChild).close()
-        }
-
-        then:
-        !output.contains(WARNING)
-    }
-
-    void 'a many-to-many with a Map on one side logs no warning, because the Map side writes the join table'() {
-        when:
-        var output = stderrWhile {
-            new HibernateDatastore(WarnMapLeft, WarnMapRight).close()
-        }
-
-        then:
-        !output.contains(WARNING)
-    }
-
-    void 'a many-to-many with a Map on both sides logs no warning'() {
-        when:
-        var output = stderrWhile {
-            new HibernateDatastore(WarnMapBothLeft, WarnMapBothRight).close()
-        }
-
-        then:
-        !output.contains(WARNING)
-    }
-
-    void 'the relationship is stored when it is written through the Map side'() {
-        given:
-        HibernateDatastore datastore = new HibernateDatastore(WarnMapLeft, WarnMapRight)
-
-        when:
-        WarnMapLeft.withNewTransaction {
-            WarnMapRight right = new WarnMapRight(name: 'right').save(failOnError: true)
-            new WarnMapLeft(name: 'left', rights: [first: right]).save(failOnError: true)
-        }
-
-        then:
-        WarnMapLeft.withNewSession {
-            WarnMapLeft.findByName('left').rights.keySet() == ['first'] as Set
-        }
-        WarnMapRight.withNewSession {
-            WarnMapRight.findByName('right').lefts*.name == ['left']
-        }
-
-        cleanup:
-        datastore?.close()
-    }
-
-    private static String stderrWhile(Closure<?> work) {
-        var original = System.err
-        var buffer = new ByteArrayOutputStream()
-        System.setErr(new PrintStream(buffer, true))
-        try {
-            work()
-        }
-        finally {
-            System.setErr(original)
-        }
-        buffer.toString()
-    }
-}
-
-@Entity
-class WarnNoOwnerLeft {
-
-    String name
-    Set<WarnNoOwnerRight> rights
-
-    static hasMany = [rights: WarnNoOwnerRight]
-}
-
-@Entity
-class WarnNoOwnerRight {
-
-    String name
-    Set<WarnNoOwnerLeft> lefts
-
-    static hasMany = [lefts: WarnNoOwnerLeft]
-}
-
-@Entity
-class WarnOwnedLeft {
-
-    String name
-    Set<WarnOwnerRight> owners
-
-    static hasMany = [owners: WarnOwnerRight]
-    static belongsTo = WarnOwnerRight
-}
-
-@Entity
-class WarnOwnerRight {
-
-    String name
-    Set<WarnOwnedLeft> lefts
-
-    static hasMany = [lefts: WarnOwnedLeft]
-}
-
-@Entity
-class WarnSelfReferencing {
-
-    String name
-    Set<WarnSelfReferencing> friends
-
-    static hasMany = [friends: WarnSelfReferencing]
-}
-
-@Entity
-class WarnCircular {
-
-    String name
-    Set<WarnCircular> following
-    Set<WarnCircular> followers
-
-    static hasMany = [following: WarnCircular, followers: WarnCircular]
-    static mappedBy = [following: 'followers', followers: 'following']
-}
-
-@Entity
-class WarnCircularOwned {
-
-    String name
-    Set<WarnCircularOwned> following
-    Set<WarnCircularOwned> followers
-
-    static hasMany = [following: WarnCircularOwned, followers: WarnCircularOwned]
-    static mappedBy = [following: 'followers', followers: 'following']
-    static belongsTo = WarnCircularOwned
-}
-
-@Entity
-class WarnParent {
-
-    String name
-    Set<WarnChild> children
-    Set<String> labels
-
-    static hasMany = [children: WarnChild, labels: String]
-}
-
-@Entity
-class WarnChild {
-
-    String name
-}
-
-@Entity
-class WarnMapLeft {
-
-    String name
-    Map<String, WarnMapRight> rights
-
-    static hasMany = [rights: WarnMapRight]
-}
-
-@Entity
-class WarnMapRight {
-
-    String name
-    Set<WarnMapLeft> lefts
-
-    static hasMany = [lefts: WarnMapLeft]
-}
-
-@Entity
-class WarnMapBothLeft {
-
-    String name
-    Map<String, WarnMapBothRight> rights
-
-    static hasMany = [rights: WarnMapBothRight]
-}
-
-@Entity
-class WarnMapBothRight {
-
-    String name
-    Map<String, WarnMapBothLeft> lefts
-
-    static hasMany = [lefts: WarnMapBothLeft]
-}
diff --git a/grails-data-hibernate7/core/src/test/resources/classic-oracle/ddl-differential.txt b/grails-data-hibernate7/core/src/test/resources/classic-oracle/ddl-differential.txt
index d46d11d4b7..82c6b14d7f 100644
--- a/grails-data-hibernate7/core/src/test/resources/classic-oracle/ddl-differential.txt
+++ b/grails-data-hibernate7/core/src/test/resources/classic-oracle/ddl-differential.txt
@@ -4139,10 +4139,6 @@ table	smbssingle_super	{"checks":[],"collections":[],"columnOrder":["id","versio
 script		"CREATE MEMORY TABLE \"PUBLIC\".\"SMBSSINGLE_SUPER\"(\n    \"ID\" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,\n    \"VERSION\" BIGINT NOT NULL,\n    \"CLASS\" CHARACTER VARYING(255) NOT NULL,\n    \"NAME\" CHARACTER VARYING(255),\n    \"SUB_NAME\" CHARACTER VARYING(255)\n);"
 script		"ALTER TABLE \"PUBLIC\".\"SMBSSINGLE_SUPER\" ADD CONSTRAINT \"PUBLIC\".\"CONSTRAINT_#\" PRIMARY KEY(\"ID\");"
 @group	org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSub	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSub","org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSuper"],"unbootable":"MissingPropertyException: No such property: checkConstraints for class: org.hibernate.mapping.DenormalizedTable"}
-@group	org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault","org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassRoot","org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassSub"]}
-table	single_table_sub_class_root	{"checks":[],"collections":[],"columnOrder":["id","version","class","label","name"],"columns":{"class":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null,"identity":false,"nullable":false,"type":"varchar(255)","unique":false},"id":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null,"identity":true,"nullable":false,"type":"bigint","unique":false},"label":{"checks":[],"collation":null,"comment":null,"d [...]
-script		"CREATE MEMORY TABLE \"PUBLIC\".\"SINGLE_TABLE_SUB_CLASS_ROOT\"(\n    \"ID\" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,\n    \"VERSION\" BIGINT NOT NULL,\n    \"CLASS\" CHARACTER VARYING(255) NOT NULL,\n    \"LABEL\" CHARACTER VARYING(255),\n    \"NAME\" CHARACTER VARYING(255)\n);"
-script		"ALTER TABLE \"PUBLIC\".\"SINGLE_TABLE_SUB_CLASS_ROOT\" ADD CONSTRAINT \"PUBLIC\".\"CONSTRAINT_#\" PRIMARY KEY(\"ID\");"
 @group	org.grails.orm.hibernate.cfg.domainbinding.binder.TestEntity	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.TestEntity"]}
 table	test_entity	{"checks":[],"collections":[],"columnOrder":["id","version","name"],"columns":{"id":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null,"identity":true,"nullable":false,"type":"bigint","unique":false},"name":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null,"identity":false,"nullable":true,"type":"varchar(255)","unique":false},"version":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null, [...]
 script		"CREATE MEMORY TABLE \"PUBLIC\".\"TEST_ENTITY\"(\n    \"ID\" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,\n    \"VERSION\" BIGINT NOT NULL,\n    \"NAME\" CHARACTER VARYING(255)\n);"
diff --git a/grails-data-hibernate7/core/src/test/resources/classic-oracle/generator-differential.txt b/grails-data-hibernate7/core/src/test/resources/classic-oracle/generator-differential.txt
index 2d31db0510..1c7c7cda6f 100644
--- a/grails-data-hibernate7/core/src/test/resources/classic-oracle/generator-differential.txt
+++ b/grails-data-hibernate7/core/src/test/resources/classic-oracle/generator-differential.txt
@@ -1456,10 +1456,6 @@ entity	org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSSingleSuper	{"abstr
 @group	org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSub	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSub","org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSuper"]}
 entity	org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSub	{"abstractClass":false,"batchSize":-1,"declaredNames":["subName"],"dynamicInsert":false,"dynamicUpdate":false,"entityName":"org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSub","identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityName":"SMBSUnionSub","kind":"UnionSubclass","optimisticLock":"VERSION","ownFilters":[],"ownsTable":true,"propertyNames":["subName"],"props":{"id":{"back [...]
 entity	org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSuper	{"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version","name"],"discriminatorInsertable":true,"dynamicInsert":false,"dynamicUpdate":false,"entityName":"org.grails.orm.hibernate.cfg.domainbinding.binder.SMBSUnionSuper","generator":{"className":"org.grails.orm.hibernate.cfg.domainbinding.generator.GrailsSequenceStyleGenerator","sequence":{"incrementSize":50,"name":"smbsunion_super_SEQ","optimize [...]
-@group	org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault","org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassRoot","org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassSub"]}
-entity	org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault	{"abstractClass":false,"batchSize":-1,"declaredNames":["label"],"discriminatorValue":"org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault","dynamicInsert":false,"dynamicUpdate":false,"entityName":"org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassDefault","identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityName":"SingleTableSubClass [...]
-entity	org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassRoot	{"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version"],"discriminator":{"javaType":"java.lang.String","jdbcCode":12,"kind":"BasicValue","selectables":[{"name":"class","nullable":false,"quoted":false,"sqlType":"varchar(255)","text":"class","unique":false}],"typeName":"string","typeParameters":{},"types":["BasicValue"]},"discriminatorInsertable":true,"discriminatorValue":"org.grails.or [...]
-entity	org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassSub	{"abstractClass":false,"batchSize":-1,"declaredNames":["name"],"discriminatorValue":"SUB_CLASS","dynamicInsert":false,"dynamicUpdate":false,"entityName":"org.grails.orm.hibernate.cfg.domainbinding.binder.SingleTableSubClassSub","identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityName":"SingleTableSubClassSub","kind":"SingleTableSubclass","optimisticLock":"VERSION","ownFilters":[] [...]
 @group	org.grails.orm.hibernate.cfg.domainbinding.binder.TestEntity	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.TestEntity"]}
 entity	org.grails.orm.hibernate.cfg.domainbinding.binder.TestEntity	{"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version","name"],"discriminatorInsertable":true,"dynamicInsert":false,"dynamicUpdate":false,"entityName":"org.grails.orm.hibernate.cfg.domainbinding.binder.TestEntity","generator":{"className":"org.grails.orm.hibernate.cfg.domainbinding.generator.GrailsNativeGenerator"},"identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityN [...]
 @group	org.grails.orm.hibernate.cfg.domainbinding.binder.UnidirectionalLeft	{"members":["org.grails.orm.hibernate.cfg.domainbinding.binder.UnidirectionalLeft","org.grails.orm.hibernate.cfg.domainbinding.binder.UnidirectionalRight"]}