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 7b2daea58466ff424abee3f63021fd2364b2cd30 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Thu Oct 8 16:30:49 2026 -0500 feat: accept a formula on an enum property in native domain binding The generated mode refused an enum property mapped with a formula. The domain binder boots it and ignores the formula: the enum binder always binds a column, so the table has the enum column and the property is stored and read as usual. The generator now ignores the formula of an enum the same way, a multi-column simple property is reported as a mapping the binder cannot boot either, and the option coverage spec lists the formula on an enum among the options both bindings ignore. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- .../domainbinding/jpa/GrailsDomainGenerator.groovy | 9 +++++---- .../GeneratedDomainClassesBinderLeniencySpec.groovy | 20 ++++++++++++++++++++ .../GrailsDomainGeneratorOptionCoverageSpec.groovy | 4 +++- 3 files changed, 28 insertions(+), 5 deletions(-) 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 346c703e44..e9b81cd320 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 @@ -684,6 +684,11 @@ class GrailsDomainGenerator { isCustomProperty(property) || isEmbeddedValue(property)) && !decideType(property).supported) { return typeNotSupported(property, decideType(property)) } + PropertyConfig stated = property.hibernateMappedForm + if (stated != null && stated.columns != null && stated.columns.size() > 1) { + return "Property [${property.name}] of [${entity.name}] is mapped with ${stated.columns.size()} columns, which the binder " + + "cannot bind either: it fails with 'maps to ${stated.columns.size()} columns but 1 columns are required'" + } return "Property [${property.name}] of [${entity.name}] is a ${property.getClass().simpleName}, " + 'which the generator does not support yet' } @@ -1065,10 +1070,6 @@ class GrailsDomainGenerator { if (mappedForm.columns != null && mappedForm.columns.size() > 1) { return false } - if (property instanceof HibernateEnumProperty && mappedForm.derived) { - // the enum binder never reads the formula, it always binds a column - return false - } TypeDecision decision = decideType(property) // the binder binds a custom property like a simple one, from the type its mapping names; with none, Hibernate infers the type from // the field as the binder's resolution does (a serializable class is stored as bytes) diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesBinderLeniencySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesBinderLeniencySpec.groovy index 10c3320f75..25378a425b 100644 --- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesBinderLeniencySpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesBinderLeniencySpec.groovy @@ -95,6 +95,7 @@ class GeneratedDomainClassesBinderLeniencySpec extends Specification { 'a property of a serializable class with no type' | [GblSerializable] | 'gbl_serializable' | ['id', 'version', 'thing'] 'an embedded property that is given a user type' | [GblUserTyped] | 'gbl_user_typed' | ['id', 'version', 'home'] 'an embedded type that extends a domain class' | [GblEmbBase, GblEmbOwner] | 'gbl_emb_owner' | ['id', 'version', 'emb_id', 'emb_a', 'emb_b'] + 'an enum mapped with a formula' | [GblEnumFormula] | 'gbl_enum_formula' | ['id', 'version', 'color'] } @Unroll @@ -118,6 +119,7 @@ class GeneratedDomainClassesBinderLeniencySpec extends Specification { 'a property of a serializable class with no type' | [GblSerializable] | 'serialCycle' | ['first', 'second'] 'an embedded property that is given a user type' | [GblUserTyped] | 'userTypedCycle' | ['STREET', 'AVENUE'] 'an embedded type that extends a domain class' | [GblEmbBase, GblEmbOwner] | 'embeddedSubCycle' | ['a1/b1', 'a2/b2'] + 'an enum mapped with a formula' | [GblEnumFormula] | 'enumFormulaCycle' | ['GREEN', 'RED'] } private List tagsCycle() { @@ -176,6 +178,13 @@ class GeneratedDomainClassesBinderLeniencySpec extends Specification { return [first, GblEmbOwner.withNewSession { GblEmbOwner owner = GblEmbOwner.get(id); "${owner.emb.a}/${owner.emb.b}".toString() }] } + private List enumFormulaCycle() { + Long id = GblEnumFormula.withTransaction { new GblEnumFormula(color: GblColor.GREEN).save(failOnError: true, flush: true).id } + String first = GblEnumFormula.withNewSession { GblEnumFormula.get(id).color.name() } + GblEnumFormula.withTransaction { GblEnumFormula row = GblEnumFormula.get(id); row.color = GblColor.RED; row.save(failOnError: true, flush: true) } + return [first, GblEnumFormula.withNewSession { GblEnumFormula.get(id).color.name() }] + } + private List serialCycle() { Long id = GblSerializable.withTransaction { new GblSerializable(thing: new GblThing(a: 'first')).save(failOnError: true, flush: true).id } String first = GblSerializable.withNewSession { GblSerializable.get(id).thing.a } @@ -336,3 +345,14 @@ class GblEmbOwner { static embedded = ['emb'] } + +enum GblColor { RED, GREEN } + +@Entity +class GblEnumFormula { + GblColor color + + static mapping = { + color formula: 'upper(color)' + } +} diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorOptionCoverageSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorOptionCoverageSpec.groovy index 6d63fffdb8..b420c94bf2 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorOptionCoverageSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorOptionCoverageSpec.groovy @@ -94,7 +94,7 @@ class GrailsDomainGeneratorOptionCoverageSpec extends GrailsDomainGeneratorSuppo 'property.updatable' : COLUMN_KINDS, 'property.type' : ['basic'], 'property.typeClass' : ['basic', 'number', 'mode', 'home', 'tags', 'modes', 'targets', 'ordered'], - 'property.derived' : ['basic', 'number', 'mode', 'target'], + 'property.derived' : ['basic', 'number', 'target'], 'property.cache' : COLLECTIONS, 'property.batchSize' : COLLECTIONS, 'property.sort' : ['targets'], @@ -138,6 +138,8 @@ class GrailsDomainGeneratorOptionCoverageSpec extends GrailsDomainGeneratorSuppo 'property.updatable' : NO_COLUMN_KINDS, // the type of a foreign key column is the one of the column it references, and the binder ignores the length, precision and scale // of a collection of basic values too + // the enum binder never reads the formula of an enum property, it always binds a column + 'property.derived' : ['mode'], 'column.length' : ['target', 'tags', 'targets', 'ordered'], 'column.precision' : ['target', 'tags', 'targets', 'ordered'], 'column.scale' : ['target', 'tags', 'targets', 'ordered'],
