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 71f539162e46cad89e64d14ab82b710fc722667f Author: Walter Duque de Estrada <[email protected]> AuthorDate: Tue Oct 6 20:57:29 2026 -0500 fix(hibernate7): generated mode names the element column an owning many-to-many side states The binder gives the join table the column the owning side names (joinTable column), which upstream's inverse join table fix made visible on the inverse side too. The generator ignored it for a non-circular owning side and kept the default name of the other side's column. A circular side keeps the old naming, as the binder does. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- .../domainbinding/jpa/GrailsDomainGenerator.groovy | 9 +++++++ ...ratedDomainClassesCircularManyToManySpec.groovy | 29 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGenerator.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGenerator.groovy index 059df741c9..16456786a0 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGenerator.groovy +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGenerator.groovy @@ -1628,6 +1628,15 @@ class GrailsDomainGenerator { } // ManyToOneBinder binds the element like the other side's own column: its name rules and its (never) nullable column element = circularKeyName(other, toOneColumnFacets(other)) + String joinColumnName = joinTable?.column?.name + if (joinColumnName != null && property.owningSide && !property.isCircular()) { + // the owning side names the element column of the join table it writes (the inverse side adopts it); a circular + // side keeps naming it after the property of the other side, as the binder does + element = new ColumnFacets( + joinColumnName, element.nullable(), element.unique(), element.insertable(), element.updatable(), + element.length(), element.precision(), element.scale(), element.sqlType(), element.defaultValue(), + element.read(), element.write(), element.comment()) + } mappedBy = property.owningSide ? null : other.name } else if (property.shouldBindWithForeignKey()) { HibernateToOneProperty inverse = (HibernateToOneProperty) property.hibernateInverseSide diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesCircularManyToManySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesCircularManyToManySpec.groovy index 1ceb33c18e..f776b0c808 100644 --- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesCircularManyToManySpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesCircularManyToManySpec.groovy @@ -98,6 +98,17 @@ class GeneratedDomainClassesCircularManyToManySpec extends Specification { 'a second side that names its join key' | [CmKeyedSecond] } + void "a non-circular owning side that names the key and the column of its join table gives the generated mode the same columns"() { + when: + Map<String, Object> binder = schema([CmNamedOwner, CmNamedOther], false) + Map<String, Object> generated = schema([CmNamedOwner, CmNamedOther], true) + + then: + generated == binder + generated['grails.gorm.tests.generated.CmNamedOwner.others'].key == ['owner_ref'] + generated['grails.gorm.tests.generated.CmNamedOwner.others'].element == ['other_ref'] + } + void "the side bound first keeps the default key name and the side bound second is named after its property"() { when: Map<String, Object> generated = schema([CmFollowers], true) @@ -269,3 +280,21 @@ class CmKeyedSecond { following joinTable: [name: 'cm_keyed_second_f', key: 'owner_ref', column: 'other_ref'] } } + +@Entity +class CmNamedOwner { + String name + Set<CmNamedOther> others + static hasMany = [others: CmNamedOther] + static mapping = { + others joinTable: [name: 'cm_named_join', key: 'owner_ref', column: 'other_ref'] + } +} + +@Entity +class CmNamedOther { + String name + Set<CmNamedOwner> owners + static hasMany = [owners: CmNamedOwner] + static belongsTo = [owners: CmNamedOwner] +}
