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/05 14:43:27 UTC
(grails-core) 01/01: fix: apply comment, default, read and write of an enum column config
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch fix/hibernate7-enum-column-extras-8.0.x
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit f0ef8480cfe9e3e7a21e7f505c51d69b01efbfc6
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Mon Oct 5 08:33:04 2026 -0500
fix: apply comment, default, read and write of an enum column config
EnumTypeBinder.bindEnumType never applied the ColumnConfig comment,
defaultValue, read and write that ColumnBinder.bindColumn applies to every
other column, so the DDL silently lacked them for enum properties. They are
now applied from the property's first column config, which is where the other
column config options are already applied.
EnumTypeBinderSpec gains binder-level rows (extras set; unset without a column
config) and one that checks the bound column and the H2 schema (column default
and remarks); the extras rows failed before the fix.
Co-Authored-By: Claude Sonnet 5.5 <no...@anthropic.com>
---
.../cfg/domainbinding/binder/EnumTypeBinder.java | 4 ++
.../cfg/domainbinding/EnumTypeBinderSpec.groovy | 57 ++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
index 5a0c102280..c955d3810b 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java
@@ -102,6 +102,10 @@ public class EnumTypeBinder {
if (!pc.getColumns().isEmpty()) {
ColumnConfig columnConfig = pc.getColumns().get(0);
+ column.setComment(columnConfig.getComment());
+ column.setDefaultValue(columnConfig.getDefaultValue());
+ column.setCustomRead(columnConfig.getRead());
+ column.setCustomWrite(columnConfig.getWrite());
indexBinder.bindIndex(columnName, column, columnConfig, t);
columnConfigToColumnBinder.bindColumnConfigToColumn(column, columnConfig, pc);
}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
index d01e000a12..bb30982a1c 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy
@@ -54,6 +54,10 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
@Subject
EnumTypeBinder binder
+ void setupSpec() {
+ manager.registerDomainClasses(PersonWithColumnExtras)
+ }
+
def setup() {
def grailsDomainBinder = getGrailsDomainBinder()
def metadataBuildingContext = grailsDomainBinder.getMetadataBuildingContext()
@@ -159,6 +163,53 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
1 * columnBinder.bindColumnConfigToColumn(_, _, _)
1 * indexBinder.bindIndex("status_col", _, _, _)
}
+
+ def "should apply the comment, default value and read and write expressions of the column config"() {
+ given:
+ def table = new Table("person")
+ def property = setupProperty(PersonWithColumnExtras, "status", table)
+
+ when:
+ def column = binder.bindEnumType(property as HibernateEnumProperty, "").getColumns()[0] as org.hibernate.mapping.Column
+
+ then:
+ column.getComment() == "the status"
+ column.getDefaultValue() == "'AVAILABLE'"
+ column.getCustomRead() == "lower(status)"
+ column.getCustomWrite() == "upper(?)"
+ }
+
+ def "should leave the column extras unset when the enum property has no column config"() {
+ given:
+ def table = new Table("person")
+ def property = setupProperty(Person01, "status", table)
+
+ when:
+ def column = binder.bindEnumType(property as HibernateEnumProperty, "").getColumns()[0] as org.hibernate.mapping.Column
+
+ then:
+ column.getComment() == null
+ column.getDefaultValue() == null
+ column.getCustomRead() == null
+ column.getCustomWrite() == null
+ }
+
+ def "the column extras of an enum property reach the bound column and the schema"() {
+ given:
+ def column = getPersistentEntity(PersonWithColumnExtras).persistentClass.getProperty("status").columns[0] as org.hibernate.mapping.Column
+ def metadata = sessionFactory.currentSession
+ .createNativeQuery("select column_default, remarks from information_schema.columns " +
+ "where table_name = 'PERSON_WITH_COLUMN_EXTRAS' and column_name = 'STATUS'", Object[])
+ .uniqueResult() as Object[]
+
+ expect:
+ column.getComment() == "the status"
+ column.getDefaultValue() == "'AVAILABLE'"
+ column.getCustomRead() == "lower(status)"
+ column.getCustomWrite() == "upper(?)"
+ metadata[0].toString().contains("AVAILABLE")
+ metadata[1] == "the status"
+ }
}
// --- Supporting Classes ---
@@ -193,6 +244,12 @@ enum Status01 { AVAILABLE, OUT_OF_STOCK }
Long id; Status01 status
static mapping = { status column: "status_col", index: "idx_status" }
}
+@Entity class PersonWithColumnExtras {
+ Long id; Status01 status
+ static mapping = {
+ status comment: "the status", defaultValue: "'AVAILABLE'", read: "lower(status)", write: "upper(?)"
+ }
+}
@Entity class Clown01 extends Person01 { String clownName }
class UserTypeEnumType implements UserType {