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/09 15:48:17 UTC
(grails-core) branch 9.0.x-h7-improvement-phase3 updated (1db49ad744 -> eb82a95c44)
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a change to branch 9.0.x-h7-improvement-phase3
in repository https://gitbox.apache.org/repos/asf/grails-core.git
from 1db49ad744 docs: explain the frozen classic oracle of the differential specs to contributors
new ad60a4f0b3 feat(hibernate7): make native domain binding the default and deprecate the classic binder
new 3ad3e575ff test(hibernate7): run the suite natively by default and the classic binder on demand
new 180a626d04 test(hibernate7): state the column order native binding gives a generated change log
new a58c876310 docs(hibernate7): native domain binding is the default, classic binding is deprecated
new eb82a95c44 fix(hibernate7): accept the tenant id as a part of a composite identifier in native binding
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
gradle/hibernate7-test-config.gradle | 20 +++--
grails-data-hibernate7/README.md | 9 ++
grails-data-hibernate7/core/classic-only-specs.txt | 39 ++++++++
.../core/generated-mode-exclusions.txt | 43 ---------
.../HibernateMappingContextConfiguration.groovy | 26 +++++-
.../domainbinding/jpa/GrailsDomainGenerator.groovy | 4 +-
.../HibernateConnectionSourceSettings.groovy | 11 +--
.../additional-spring-configuration-metadata.json | 6 ++
.../gorm/tests/HibernateGormDatastoreSpec.groovy | 6 +-
.../GeneratedDomainClassesMultiTenancySpec.groovy | 58 ++++++++++++
.../core/GrailsDataHibernate7TckManager.groovy | 21 +++--
.../cfg/ClassicDomainBindingDeprecationSpec.groovy | 100 +++++++++++++++++++++
...HibernateMappingContextConfigurationSpec.groovy | 8 +-
.../GrailsDomainBinderCompositeIdDefectSpec.groovy | 11 ++-
...DomainBinderEmbeddedCollectionDefectSpec.groovy | 5 +-
.../GrailsDomainGeneratorDifferentialSpec.groovy | 6 +-
.../HibernateConnectionSourceSettingsSpec.groovy | 62 +++++++++++--
.../resources/classic-oracle/ddl-differential.txt | 4 +
.../classic-oracle/generator-differential.txt | 3 +
.../cli/DbmGenerateGormChangelogCommandSpec.groovy | 24 +++--
.../dbmigration/cli/DbmGormDiffCommandSpec.groovy | 16 +++-
.../generated/GeneratedModeSnapshotSpec.groovy | 32 +++++++
.../advancedGORMFeatures/nativeDomainBinding.adoc | 29 +++---
.../configuration/configurationReference.adoc | 2 +-
.../asciidoc/gettingStarted/hibernateVersions.adoc | 6 +-
.../src/en/guide/upgrading/upgrading90x.adoc | 44 +++++----
26 files changed, 456 insertions(+), 139 deletions(-)
create mode 100644 grails-data-hibernate7/core/classic-only-specs.txt
delete mode 100644 grails-data-hibernate7/core/generated-mode-exclusions.txt
create mode 100644 grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy
(grails-core) 05/05: fix(hibernate7): accept the tenant id as a part of a composite identifier in native binding
Posted by bo...@apache.org.
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 eb82a95c44c9680e01bca21f096a6bc85ce246b8
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Fri Oct 9 10:11:31 2026 -0500
fix(hibernate7): accept the tenant id as a part of a composite identifier in native binding
grails-test-examples/hibernate7/issue450 maps `id composite: ['id',
'tenantId']` on a multi-tenant entity. The classic binder binds the tenant
id like any other column of the key and the tenant filter compares that
column; the generator refused it as "a HibernateTenantIdProperty, which the
generator does not support yet", so the app did not start once native
binding became the default. The generator now treats a tenant id part like
a simple one. GeneratedDomainClassesMultiTenancySpec boots the mapping in
both modes, stores a row per tenant and reads each tenant's own rows back
(it failed natively with the refusal before the fix); the frozen classic
oracle gains the records of the new fixture (REFREEZE, additions only).
Three specs relied on the old default to boot the classic binder and now
state it: the classic boot of the generator differential (with the
create-drop the no-argument constructor applied, which resolves the SQL
types the records hold), and the two defect-pinning specs that build their
own datastore, one of which therefore leaves classic-only-specs.txt.
Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
---
grails-data-hibernate7/core/classic-only-specs.txt | 3 +-
.../domainbinding/jpa/GrailsDomainGenerator.groovy | 4 +-
.../GeneratedDomainClassesMultiTenancySpec.groovy | 58 ++++++++++++++++++++++
.../GrailsDomainBinderCompositeIdDefectSpec.groovy | 11 ++--
...DomainBinderEmbeddedCollectionDefectSpec.groovy | 5 +-
.../GrailsDomainGeneratorDifferentialSpec.groovy | 6 ++-
.../resources/classic-oracle/ddl-differential.txt | 4 ++
.../classic-oracle/generator-differential.txt | 3 ++
8 files changed, 84 insertions(+), 10 deletions(-)
diff --git a/grails-data-hibernate7/core/classic-only-specs.txt b/grails-data-hibernate7/core/classic-only-specs.txt
index f2b041d674..8fd78eb2f7 100644
--- a/grails-data-hibernate7/core/classic-only-specs.txt
+++ b/grails-data-hibernate7/core/classic-only-specs.txt
@@ -28,13 +28,12 @@
# InFlightMetadataCollector or MetadataBuildingContext. Only those that FAIL with a natively bound datastore are listed,
# one fully qualified class name per line; the others run and pass in both modes (every other binder-internals spec,
# the generator differential included, was run against a natively bound datastore before being left out of this list).
-# The six listed assert facts of the classic boot model (a collection table the classic binder creates, a unique key it
+# The five listed assert facts of the classic boot model (a collection table the classic binder creates, a unique key it
# drops, the type parameters it sets) or pin classic defects with @PendingFeature, which native binding does not have,
# so they only hold against a classic datastore. The list goes away with the classic binder.
#
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateBasicPropertySpec
org.grails.orm.hibernate.cfg.domainbinding.jpa.EntityCollectionKeyDefectSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainBinderEmbeddedCollectionDefectSpec
org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainBinderOptionDefectSpec
org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorSpec
org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorUniqueGroupSpec
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 59ba39334a..9a20f2b486 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
@@ -615,7 +615,9 @@ class GrailsDomainGenerator {
'does not support because Hibernate cannot state one in an identifier class. Map the properties of the ' +
'embedded class as plain properties of the identifier instead (the schema stays the same), see the ' +
'Native Domain Binding chapter of the manual'
- } else if (!(part instanceof HibernateSimpleProperty) || isDerived(part)) {
+ } else if (!(part instanceof HibernateSimpleProperty || part instanceof HibernateTenantIdProperty) || isDerived(part)) {
+ // the tenant id of a multi-tenant entity is bound like any other column of the key, and the tenant filter
+ // compares that column (CompositeIdBinder gives it no special treatment either)
return "Composite identifier part [${part.name}] of [${entity.name}] is a ${part.getClass().simpleName}, which the " +
'generator does not support yet'
} else if (!supports(part)) {
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesMultiTenancySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesMultiTenancySpec.groovy
index dc658a7470..b17e877d6b 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesMultiTenancySpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/generated/GeneratedDomainClassesMultiTenancySpec.groovy
@@ -23,6 +23,7 @@ import grails.gorm.annotation.Entity
import org.hibernate.dialect.H2Dialect
import spock.lang.AutoCleanup
import spock.lang.Specification
+import spock.lang.Unroll
import spock.util.environment.RestoreSystemProperties
import org.grails.datastore.mapping.core.DatastoreUtils
@@ -79,6 +80,52 @@ class GeneratedDomainClassesMultiTenancySpec extends Specification {
GdcTenantItem.withNewSession { GdcTenantItem.list()*.name } == ['mustang']
GdcTenantItem.withNewSession { GdcTenantItem.findByName('model s') } == null
}
+
+ /**
+ * The tenant id may be a part of a composite identifier (grails-test-examples/hibernate7/issue450): the classic binder binds
+ * the part like any other column of the key, and the tenant filter compares the same column.
+ */
+ @Unroll
+ def "the tenant id can be a part of the composite identifier (generated: #generated)"() {
+ given:
+ System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, 'grails')
+ datastore = new HibernateDatastore(DatastoreUtils.createPropertyResolver([
+ 'grails.gorm.multiTenancy.mode' : MultiTenancySettings.MultiTenancyMode.DISCRIMINATOR,
+ 'grails.gorm.multiTenancy.tenantResolverClass': SystemPropertyTenantResolver.name,
+ 'dataSource.url' : "jdbc:h2:mem:gdcTenantComposite${generated};LOCK_TIMEOUT=10000".toString(),
+ 'dataSource.dialect' : H2Dialect.name,
+ 'hibernate.cache.queries' : 'false',
+ 'hibernate.cache.use_query_cache' : 'false',
+ 'hibernate.hbm2ddl.auto' : 'create',
+ 'hibernate.generatedDomainClasses' : generated,
+ ]), GdcTenantCompositeBook)
+ String grailsId = UUID.randomUUID().toString()
+ String groovyId = UUID.randomUUID().toString()
+
+ when:
+ GdcTenantCompositeBook.withTransaction {
+ new GdcTenantCompositeBook(id: grailsId, title: 'The definitive Guide to Grails 2').save(flush: true, failOnError: true)
+ }
+ System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, 'groovy')
+ GdcTenantCompositeBook.withTransaction {
+ new GdcTenantCompositeBook(id: groovyId, title: 'Groovy in Action').save(flush: true, failOnError: true)
+ }
+
+ then: 'the primary key spans both parts and the tenant id is stored with the row'
+ datastore.sessionFactory.mappingMetamodel.getEntityDescriptor(GdcTenantCompositeBook).identifierMapping.jdbcTypeCount == 2
+ GdcTenantCompositeBook.withNewSession { GdcTenantCompositeBook.list()*.title } == ['Groovy in Action']
+ GdcTenantCompositeBook.withNewSession { GdcTenantCompositeBook.list().collect { [it.id, it.tenantId] } } == [[groovyId, 'groovy']]
+
+ when:
+ System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, 'grails')
+
+ then:
+ GdcTenantCompositeBook.withNewSession { GdcTenantCompositeBook.list()*.title } == ['The definitive Guide to Grails 2']
+ GdcTenantCompositeBook.withNewSession { GdcTenantCompositeBook.findByTitle('Groovy in Action') } == null
+
+ where:
+ generated << [false, true]
+ }
}
@Entity
@@ -86,3 +133,14 @@ class GdcTenantItem implements MultiTenant<GdcTenantItem> {
String name
String tenantId
}
+
+@Entity
+class GdcTenantCompositeBook implements MultiTenant<GdcTenantCompositeBook>, Serializable {
+ String id
+ String tenantId
+ String title
+
+ static mapping = {
+ id composite: ['id', 'tenantId']
+ }
+}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderCompositeIdDefectSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderCompositeIdDefectSpec.groovy
index 259cb100e0..d391992d3f 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderCompositeIdDefectSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderCompositeIdDefectSpec.groovy
@@ -43,10 +43,13 @@ import spock.lang.PendingFeature
*/
class GrailsDomainBinderCompositeIdDefectSpec extends HibernateGormDatastoreSpec {
+ /** The defects are the classic binder's, so the datastores select it whatever the default is. */
+ private static final Map<String, Object> CLASSIC = ['hibernate.generatedDomainClasses': false]
+
@PendingFeature(reason = 'the key of a join table to a composite identifier gets the columns of the element, so Hibernate refuses the foreign key')
void "a unidirectional collection of entities with a composite identifier can be bound"() {
when:
- HibernateDatastore datastore = new HibernateDatastore(UnbootableJoinToComposite, UnbootableComposite)
+ HibernateDatastore datastore = new HibernateDatastore(CLASSIC, UnbootableJoinToComposite, UnbootableComposite)
then:
notThrown(Exception)
@@ -58,7 +61,7 @@ class GrailsDomainBinderCompositeIdDefectSpec extends HibernateGormDatastoreSpec
@PendingFeature(reason = 'ForeignKeyColumnCountCalculator counts a composite identifier part that refers to an entity with a simple identifier as no column, so the foreign key has fewer columns than the key and Hibernate refuses it')
void "a foreign key to a composite identifier with a part that refers to an entity can be bound"() {
when:
- HibernateDatastore datastore = new HibernateDatastore(UnbootableRefToParts, UnbootableParts, UnbootableTarget)
+ HibernateDatastore datastore = new HibernateDatastore(CLASSIC, UnbootableRefToParts, UnbootableParts, UnbootableTarget)
then:
notThrown(Exception)
@@ -70,7 +73,7 @@ class GrailsDomainBinderCompositeIdDefectSpec extends HibernateGormDatastoreSpec
@PendingFeature(reason = 'CompositeIdentifierToManyToOneBinder expands a nested composite identifier one level only, so a foreign key to a composite identifier three levels deep has fewer columns than the key')
void "a foreign key to a composite identifier three levels deep can be bound"() {
when:
- HibernateDatastore datastore = new HibernateDatastore(UnbootableRefToTop, UnbootableTop, UnbootableMiddle, UnbootableFlat)
+ HibernateDatastore datastore = new HibernateDatastore(CLASSIC, UnbootableRefToTop, UnbootableTop, UnbootableMiddle, UnbootableFlat)
then:
notThrown(Exception)
@@ -82,7 +85,7 @@ class GrailsDomainBinderCompositeIdDefectSpec extends HibernateGormDatastoreSpec
@PendingFeature(reason = 'the key of a joined subclass is bound with one column, so a joined subclass of an entity with a composite identifier cannot be bound')
void "a joined subclass of an entity with a composite identifier can be bound"() {
when:
- HibernateDatastore datastore = new HibernateDatastore(UnbootableJoinedParent, UnbootableJoinedChild)
+ HibernateDatastore datastore = new HibernateDatastore(CLASSIC, UnbootableJoinedParent, UnbootableJoinedChild)
then:
notThrown(Exception)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderEmbeddedCollectionDefectSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderEmbeddedCollectionDefectSpec.groovy
index 8ccdc5c09a..b8be64ee3d 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderEmbeddedCollectionDefectSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainBinderEmbeddedCollectionDefectSpec.groovy
@@ -33,10 +33,13 @@ import spock.lang.PendingFeature
*/
class GrailsDomainBinderEmbeddedCollectionDefectSpec extends HibernateGormDatastoreSpec {
+ /** The defects are the classic binder's, so the datastores select it whatever the default is. */
+ private static final Map<String, Object> CLASSIC = ['hibernate.generatedDomainClasses': false]
+
@PendingFeature(reason = 'the role, the table and the key column of a collection inside an embedded type come from the type, so two owners of the type collide')
void "two entities can embed a type that has a collection"() {
when:
- HibernateDatastore datastore = new HibernateDatastore(EmbeddedCollectionOwnerA, EmbeddedCollectionOwnerB)
+ HibernateDatastore datastore = new HibernateDatastore(CLASSIC, EmbeddedCollectionOwnerA, EmbeddedCollectionOwnerB)
then:
notThrown(Exception)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorDifferentialSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorDifferentialSpec.groovy
index 07c110c9f1..dabc6f22b1 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorDifferentialSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/jpa/GrailsDomainGeneratorDifferentialSpec.groovy
@@ -460,7 +460,7 @@ class GrailsDomainGeneratorDifferentialSpec extends HibernateGormDatastoreSpec {
}
/**
- * Boots a group of entities with the classic binder. GORM only gives an entity a tenant id (and the binder only adds the tenant filter) in
+ * Boots a group of entities with the classic binder (stated, since native binding is the default). GORM only gives an entity a tenant id (and the binder only adds the tenant filter) in
* discriminator multi-tenancy mode, so a group with multi-tenant entities is booted in that mode when it can be.
*/
private static HibernateDatastore boot(List<Class<?>> group) {
@@ -468,6 +468,7 @@ class GrailsDomainGeneratorDifferentialSpec extends HibernateGormDatastoreSpec {
try {
return new HibernateDatastore([
'dataSource.dbCreate' : 'create-drop',
+ 'hibernate.generatedDomainClasses' : false,
'grails.gorm.multiTenancy.mode' : MultiTenancySettings.MultiTenancyMode.DISCRIMINATOR,
'grails.gorm.multiTenancy.tenantResolver': new SystemPropertyTenantResolver(),
], group as Class[])
@@ -475,7 +476,8 @@ class GrailsDomainGeneratorDifferentialSpec extends HibernateGormDatastoreSpec {
// a domain that needs another configuration is booted by default below
}
}
- return new HibernateDatastore(group as Class[])
+ // the same create-drop the no-argument constructor applies, which resolves the SQL types the records hold
+ return new HibernateDatastore(['dataSource.dbCreate': 'create-drop', 'hibernate.generatedDomainClasses': false], group as Class[])
}
/**
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 a66a4cd1bd..584d2f9b27 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
@@ -1546,6 +1546,10 @@ script "ALTER TABLE \"PUBLIC\".\"GDC_TENANT_AUTHOR\" ADD CONSTRAINT \"PUBLIC\".
script "CREATE MEMORY TABLE \"PUBLIC\".\"GDC_TENANT_BOOK\"(\n \"AUTHOR_ID\" BIGINT,\n \"ID\" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,\n \"VERSION\" BIGINT NOT NULL,\n \"TITLE\" CHARACTER VARYING(255)\n);"
script "ALTER TABLE \"PUBLIC\".\"GDC_TENANT_BOOK\" ADD CONSTRAINT \"PUBLIC\".\"CONSTRAINT_#\" PRIMARY KEY(\"ID\");"
script "ALTER TABLE \"PUBLIC\".\"GDC_TENANT_BOOK\" ADD CONSTRAINT \"PUBLIC\".\"FKREGPA62G053JK0RFAO4IMN072\" FOREIGN KEY(\"AUTHOR_ID\") REFERENCES \"PUBLIC\".\"GDC_TENANT_AUTHOR\"(\"ID\") NOCHECK;"
+@group grails.gorm.tests.generated.GdcTenantCompositeBook {"members":["grails.gorm.tests.generated.GdcTenantCompositeBook"]}
+table gdc_tenant_composite_book {"checks":[],"collections":[],"columnOrder":["version","id","tenant_id","title"],"columns":{"id":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null,"identity":false,"nullable":false,"type":"varchar(255)","unique":false},"tenant_id":{"checks":[],"collation":null,"comment":null,"default":null,"generatedAs":null,"identity":false,"nullable":false,"type":"varchar(255)","unique":false},"title":{"checks":[],"collation":null,"comment":n [...]
+script "CREATE MEMORY TABLE \"PUBLIC\".\"GDC_TENANT_COMPOSITE_BOOK\"(\n \"VERSION\" BIGINT NOT NULL,\n \"ID\" CHARACTER VARYING(255) NOT NULL,\n \"TENANT_ID\" CHARACTER VARYING(255) NOT NULL,\n \"TITLE\" CHARACTER VARYING(255)\n);"
+script "ALTER TABLE \"PUBLIC\".\"GDC_TENANT_COMPOSITE_BOOK\" ADD CONSTRAINT \"PUBLIC\".\"CONSTRAINT_#\" PRIMARY KEY(\"ID\", \"TENANT_ID\");"
@group grails.gorm.tests.generated.GdcTenantItem {"members":["grails.gorm.tests.generated.GdcTenantItem"]}
table gdc_tenant_item {"checks":[],"collections":[],"columnOrder":["id","version","name","tenant_id"],"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},"tenant_id":{"checks":[],"collation":null,"comment":null,"default":null," [...]
script "CREATE MEMORY TABLE \"PUBLIC\".\"GDC_TENANT_ITEM\"(\n \"ID\" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,\n \"VERSION\" BIGINT NOT NULL,\n \"NAME\" CHARACTER VARYING(255),\n \"TENANT_ID\" 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 b14f1f717d..355739310a 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
@@ -506,6 +506,9 @@ entity grails.gorm.tests.generated.GdcSerPet {"abstractClass":false,"batchSize":
@group grails.gorm.tests.generated.GdcTenantAuthor {"members":["grails.gorm.tests.generated.GdcTenantAuthor","grails.gorm.tests.generated.GdcTenantBook"]}
entity grails.gorm.tests.generated.GdcTenantAuthor {"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version","name","books"],"discriminatorInsertable":true,"dynamicInsert":false,"dynamicUpdate":false,"entityName":"grails.gorm.tests.generated.GdcTenantAuthor","generator":{"className":"org.grails.orm.hibernate.cfg.domainbinding.generator.GrailsNativeGenerator"},"identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityName":"GdcTenantAuthor","ki [...]
entity grails.gorm.tests.generated.GdcTenantBook {"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version","title","author"],"discriminatorInsertable":true,"dynamicInsert":false,"dynamicUpdate":false,"entityName":"grails.gorm.tests.generated.GdcTenantBook","generator":{"className":"org.grails.orm.hibernate.cfg.domainbinding.generator.GrailsNativeGenerator"},"identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityName":"GdcTenantBook","kind": [...]
+@group grails.gorm.tests.generated.GdcTenantCompositeBook {"members":["grails.gorm.tests.generated.GdcTenantCompositeBook"]}
+entity grails.gorm.tests.generated.GdcTenantCompositeBook {"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version","title"],"discriminatorInsertable":true,"dynamicInsert":false,"dynamicUpdate":false,"entityName":"grails.gorm.tests.generated.GdcTenantCompositeBook","identifier":{"embedded":true,"kind":"Component","members":[{"backref":false,"insertable":true,"lazy":false,"name":"id","naturalIdentifier":false,"optional":false,"updateable":true,"value":{"javaType":"jav [...]
+filter tenantId {"appliedToLoadByKey":false,"autoEnabled":false,"name":"tenantId","parameterNames":["tenantId"],"parameterTypes":{"tenantId":"java.lang.String"}}
@group grails.gorm.tests.generated.GdcTenantItem {"members":["grails.gorm.tests.generated.GdcTenantItem"]}
entity grails.gorm.tests.generated.GdcTenantItem {"abstractClass":false,"batchSize":0,"cached":false,"declaredNames":["version","name","tenantId"],"discriminatorInsertable":true,"dynamicInsert":false,"dynamicUpdate":false,"entityName":"grails.gorm.tests.generated.GdcTenantItem","generator":{"className":"org.grails.orm.hibernate.cfg.domainbinding.generator.GrailsNativeGenerator"},"identifierKind":"BasicValue","identifierProperty":"id","joinTables":{},"jpaEntityName":"GdcTenantItem","kind" [...]
filter tenantId {"appliedToLoadByKey":false,"autoEnabled":false,"name":"tenantId","parameterNames":["tenantId"],"parameterTypes":{"tenantId":"java.lang.String"}}
(grails-core) 03/05: test(hibernate7): state the column order native binding gives a generated change log
Posted by bo...@apache.org.
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 180a626d04928cee377575af2a7ac3cf50122d28
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Fri Oct 9 09:36:02 2026 -0500
test(hibernate7): state the column order native binding gives a generated change log
With native binding the default, dbm-generate-gorm-changelog and
dbm-gorm-diff list the columns of a createTable change set in the order
Hibernate's annotation binder bound them: the identifier, the other
properties sorted by name (the version among them), then the foreign keys
of the second pass. Classic binding listed the identifier, the version,
then the properties in declaration order. Hibernate only reorders the
columns of the mapping model when a schema action is configured, which the
migration commands do not set, so the two CLI specs that spelled out the
classic order now state the native one, with the reason, and
GeneratedModeSnapshotSpec pins the rule in both modes. Liquibase does not
compare column order, so a diff against an existing database is unchanged.
The deprecation spec's "default" feature follows the mode of the suite:
with -Pgrails.test.classicDomainBinding=true the classic binder is the
default and the warning is expected.
Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
---
.../cfg/ClassicDomainBindingDeprecationSpec.groovy | 5 +++-
.../cli/DbmGenerateGormChangelogCommandSpec.groovy | 24 ++++++++++------
.../dbmigration/cli/DbmGormDiffCommandSpec.groovy | 16 ++++++++---
.../generated/GeneratedModeSnapshotSpec.groovy | 32 ++++++++++++++++++++++
4 files changed, 64 insertions(+), 13 deletions(-)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy
index 8aef741e79..9029f3059d 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy
@@ -76,11 +76,14 @@ class ClassicDomainBindingDeprecationSpec extends Specification {
}
void "the default, native domain binding, starts without the warning"() {
+ given: 'the suite may run through the classic binder as a whole, which makes the classic binder the default'
+ boolean classicSuite = Boolean.getBoolean('grails.hibernate.classicDomainBinding')
+
when:
String log = bootAndCaptureLog([:])
then:
- !log.contains(WARNING)
+ log.contains(WARNING) == classicSuite
DomainOne.withTransaction {
new DomainOne(controller: 'book', action: 'native').save(flush: true, failOnError: true)
DomainOne.count() == 1
diff --git a/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGenerateGormChangelogCommandSpec.groovy b/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGenerateGormChangelogCommandSpec.groovy
index 8ef523c163..2a9d7aa86a 100644
--- a/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGenerateGormChangelogCommandSpec.groovy
+++ b/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGenerateGormChangelogCommandSpec.groovy
@@ -28,6 +28,14 @@ class DbmGenerateGormChangelogCommandSpec extends ApplicationContextDatabaseMigr
return DbmGenerateGormChangelogCommand
}
+ // Native domain binding (the default) lists the columns of a table in the order Hibernate's annotation binder binds
+ // them: the identifier, then the other properties sorted by name (the version among them), then the foreign keys it
+ // resolves in a second pass. Classic binding listed the identifier, the version, then the properties in declaration
+ // order. Hibernate only reorders the columns of the mapping model when a schema action (hbm2ddl.auto / dbCreate) is
+ // configured, which the migration commands do not set, so the generated change log shows the binding order. The
+ // snapshot of an existing database is not affected: Liquibase does not compare column order. See
+ // GeneratedModeSnapshotSpec and the "Differences in the Schema" section of the Native Domain Binding chapter.
+
def "writes Change Log to copy the current state of the database to STDOUT"() {
when:
command.handle(getExecutionContext())
@@ -42,11 +50,11 @@ databaseChangeLog = \\{
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "authorPK"\\)
\\}
- column\\(name: "version", type: "BIGINT"\\) \\{
+ column\\(name: "name", type: "VARCHAR\\(255\\)"\\) \\{
constraints\\(nullable: "false"\\)
\\}
- column\\(name: "name", type: "VARCHAR\\(255\\)"\\) \\{
+ column\\(name: "version", type: "BIGINT"\\) \\{
constraints\\(nullable: "false"\\)
\\}
\\}
@@ -58,11 +66,11 @@ databaseChangeLog = \\{
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
- column\\(name: "version", type: "BIGINT"\\) \\{
+ column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
constraints\\(nullable: "false"\\)
\\}
- column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
+ column\\(name: "version", type: "BIGINT"\\) \\{
constraints\\(nullable: "false"\\)
\\}
@@ -97,11 +105,11 @@ databaseChangeLog = \\{
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "authorPK"\\)
\\}
- column\\(name: "version", type: "BIGINT"\\) \\{
+ column\\(name: "name", type: "VARCHAR\\(255\\)"\\) \\{
constraints\\(nullable: "false"\\)
\\}
- column\\(name: "name", type: "VARCHAR\\(255\\)"\\) \\{
+ column\\(name: "version", type: "BIGINT"\\) \\{
constraints\\(nullable: "false"\\)
\\}
\\}
@@ -113,11 +121,11 @@ databaseChangeLog = \\{
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
- column\\(name: "version", type: "BIGINT"\\) \\{
+ column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
constraints\\(nullable: "false"\\)
\\}
- column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
+ column\\(name: "version", type: "BIGINT"\\) \\{
constraints\\(nullable: "false"\\)
\\}
diff --git a/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGormDiffCommandSpec.groovy b/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGormDiffCommandSpec.groovy
index 801e6d5c35..9ef0a38ae4 100644
--- a/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGormDiffCommandSpec.groovy
+++ b/grails-data-hibernate7/dbmigration/src/test-cli/groovy/org/apache/grails/data/hibernate7/dbmigration/cli/DbmGormDiffCommandSpec.groovy
@@ -32,6 +32,14 @@ class DbmGormDiffCommandSpec extends ApplicationContextDatabaseMigrationCommandS
sql.executeUpdate 'CREATE TABLE PUBLIC.author (id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, version BIGINT NOT NULL, name VARCHAR(255) NOT NULL, CONSTRAINT authorPK PRIMARY KEY (id));'
}
+ // Native domain binding (the default) lists the columns of a table in the order Hibernate's annotation binder binds
+ // them: the identifier, then the other properties sorted by name (the version among them), then the foreign keys it
+ // resolves in a second pass. Classic binding listed the identifier, the version, then the properties in declaration
+ // order. Hibernate only reorders the columns of the mapping model when a schema action (hbm2ddl.auto / dbCreate) is
+ // configured, which the migration commands do not set, so the generated change log shows the binding order. The
+ // snapshot of an existing database is not affected: Liquibase does not compare column order. See
+ // GeneratedModeSnapshotSpec and the "Differences in the Schema" section of the Native Domain Binding chapter.
+
def "diffs GORM classes against a database and generates a changelog to STDOUT"() {
when:
command.handle(getExecutionContext())
@@ -46,11 +54,11 @@ databaseChangeLog = \\{
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
- column\\(name: "version", type: "BIGINT"\\) \\{
+ column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
constraints\\(nullable: "false"\\)
\\}
- column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
+ column\\(name: "version", type: "BIGINT"\\) \\{
constraints\\(nullable: "false"\\)
\\}
@@ -85,11 +93,11 @@ databaseChangeLog = \\{
constraints\\(nullable:"false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
- column\\(name: "version", type: "BIGINT"\\) \\{
+ column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
constraints\\(nullable: "false"\\)
\\}
- column\\(name: "title", type: "VARCHAR\\(255\\)"\\) \\{
+ column\\(name: "version", type: "BIGINT"\\) \\{
constraints\\(nullable: "false"\\)
\\}
diff --git a/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/generated/GeneratedModeSnapshotSpec.groovy b/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/generated/GeneratedModeSnapshotSpec.groovy
index ec32c4f3d9..08bbd05a20 100644
--- a/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/generated/GeneratedModeSnapshotSpec.groovy
+++ b/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/generated/GeneratedModeSnapshotSpec.groovy
@@ -41,9 +41,11 @@ import liquibase.structure.core.PrimaryKey
import liquibase.structure.core.Sequence
import liquibase.structure.core.Table
import liquibase.structure.core.UniqueConstraint
+import org.hibernate.boot.spi.MetadataImplementor
import org.hibernate.dialect.H2Dialect
import spock.lang.AutoCleanup
import spock.lang.Specification
+import spock.lang.Unroll
import org.grails.orm.hibernate.HibernateDatastore
import org.grails.plugins.databasemigration.liquibase.GormDatabase
@@ -184,6 +186,36 @@ class GeneratedModeSnapshotSpec extends Specification {
binder - generated == []
generated - binder == []
}
+ /**
+ * The order of the columns of a table in the generated change log is the order Hibernate's mapping model holds them,
+ * because the migration commands configure no schema action and Hibernate only reorders the columns of the model for
+ * one (hbm2ddl.auto / dbCreate). Hibernate's annotation binder, which native binding uses, binds the persistent
+ * attributes of a class sorted by name, so after the identifier the columns follow the names of the properties, the
+ * version among them, and the foreign keys it resolves in a second pass come last. The classic binder listed the
+ * identifier, the version, then the properties in declaration order. Liquibase does not compare the order of
+ * columns, so dbm-gorm-diff against an existing database is not affected; only a createTable change set lists them
+ * in the new order.
+ */
+ @Unroll
+ def "without a schema action the columns of a table are in the order the binding created them (generated: #generated)"() {
+ when:
+ boot(generated, [SnapAuthor, SnapBook])
+
+ then:
+ tableColumns('snap_book') == columns
+
+ where:
+ generated | columns
+ false | ['id', 'version', 'title', 'isbn', 'author_id']
+ true | ['id', 'isbn', 'title', 'version', 'author_id']
+ }
+
+ private List<String> tableColumns(String table) {
+ org.hibernate.mapping.Table mapping = ((MetadataImplementor) datastore.metadata).collectTableMappings().find {
+ it.name.equalsIgnoreCase(table)
+ }
+ return mapping.columns*.name*.toLowerCase()
+ }
}
enum SnapStatus { OPEN, CLOSED }
(grails-core) 01/05: feat(hibernate7): make native domain binding the default and deprecate the classic binder
Posted by bo...@apache.org.
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 ad60a4f0b3cffeb140e7d8a487fa08e0b10f6af7
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Thu Oct 8 22:11:34 2026 -0500
feat(hibernate7): make native domain binding the default and deprecate the classic binder
hibernate.generatedDomainClasses now defaults to true, in the settings
(HibernateConnectionSourceSettings), in the configuration a session factory
is built from (HibernateMappingContextConfiguration, for the callers that
construct it themselves) and in the published configuration metadata, which
is what an IDE shows as the default and was missing the key.
Native binding accepts every mapping the classic binder can use and is
checked against the frozen classic oracle, so the classic binder is now the
fallback: false still selects it, and the configuration logs one WARN per
data source at startup saying it is deprecated and will be removed, naming
the setting. The test-only JVM property that seeded the default is inverted
(grails.hibernate.classicDomainBinding) so a suite can still run through the
classic binder as a whole.
The specs cover the defaults, the configured value, the inverted JVM
property, the metadata default and the warning (captured from the stderr
the test logger writes to), booting with an existing fixture so the entity
set of the differential specs is unchanged.
Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
---
.../HibernateMappingContextConfiguration.groovy | 26 +++++-
.../HibernateConnectionSourceSettings.groovy | 11 +--
.../additional-spring-configuration-metadata.json | 6 ++
.../cfg/ClassicDomainBindingDeprecationSpec.groovy | 97 ++++++++++++++++++++++
...HibernateMappingContextConfigurationSpec.groovy | 8 +-
.../HibernateConnectionSourceSettingsSpec.groovy | 62 ++++++++++++--
6 files changed, 188 insertions(+), 22 deletions(-)
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfiguration.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfiguration.groovy
index 63c4be38e5..592223712f 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfiguration.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfiguration.groovy
@@ -43,6 +43,8 @@ import org.hibernate.cfg.JdbcSettings
import org.hibernate.context.spi.CurrentSessionContext
import org.hibernate.internal.util.config.ConfigurationHelper
import org.hibernate.service.ServiceRegistry
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
import org.springframework.beans.BeansException
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
@@ -87,6 +89,17 @@ class HibernateMappingContextConfiguration extends Configuration
private static final long serialVersionUID = -7115087342689305517L
+ private static final Logger LOG = LoggerFactory.getLogger(HibernateMappingContextConfiguration)
+
+ /**
+ * The warning logged once per session factory when the classic domain binding is selected.
+ */
+ static final String CLASSIC_DOMAIN_BINDING_DEPRECATED =
+ 'Classic domain binding is deprecated and will be removed: hibernate.generatedDomainClasses is false ' +
+ 'for data source [%s]. Native domain binding, the default, binds the domain classes with Hibernate\'s own ' +
+ 'annotation binder; remove the setting, or set it to true, after reviewing the Native Domain Binding chapter ' +
+ 'of the GORM for Hibernate 7 manual.'
+
private static final String RESOURCE_PATTERN = '/**/*.class'
private static final TypeFilter[] ENTITY_TYPE_FILTERS = [
@@ -110,16 +123,18 @@ class HibernateMappingContextConfiguration extends Configuration
private transient ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver()
private transient NamingStrategyProvider namingStrategyProvider = new NamingStrategyProvider()
protected GrailsBytecodeProvider bytecodeProvider
- private boolean generatedDomainClasses
+ private boolean generatedDomainClasses = true
/**
- * Whether Hibernate's annotation binder binds classes generated from the GORM mapping instead of the domain binder
- * building Hibernate's boot model by hand. The real domain classes are still what is persisted and loaded.
+ * Whether Hibernate's annotation binder binds classes generated from the GORM mapping (native domain binding, the
+ * default) instead of the classic domain binder building Hibernate's boot model by hand. The real domain classes are
+ * still what is persisted and loaded.
*
* <p>Set it before the annotated classes are added: with the switch on, {@link #addAnnotatedClass} keeps the GORM entities
* that are not JPA entities away from Hibernate's own sources (see there).</p>
*
- * @param generatedDomainClasses {@code true} to bind generated classes; {@code false} (the default) for the domain binder
+ * @param generatedDomainClasses {@code true} (the default) to bind generated classes; {@code false} for the classic
+ * domain binder, which is deprecated and will be removed
*/
void setGeneratedDomainClasses(boolean generatedDomainClasses) {
this.generatedDomainClasses = generatedDomainClasses
@@ -338,6 +353,9 @@ class HibernateMappingContextConfiguration extends Configuration
persistentEntity.setDataSourceName(dataSourceName)
}
+ if (!generatedDomainClasses) {
+ LOG.warn(String.format(CLASSIC_DOMAIN_BINDING_DEPRECATED, dataSourceName))
+ }
final GeneratedDomainClassBinder generatedBinder =
generatedDomainClasses ? new GeneratedDomainClassBinder(dataSourceName, appClassLoader) : null
final GrailsDomainBinder domainBinder = new GrailsDomainBinder(
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettings.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettings.groovy
index bc88ce91ae..4423755392 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettings.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettings.groovy
@@ -90,13 +90,14 @@ class HibernateConnectionSourceSettings extends ConnectionSourceSettings {
*/
boolean hibernateDirtyChecking = false
- // the JVM-wide system property switches the default on to run an existing test suite through the generated path; a configured value wins
+ // the JVM-wide system property switches the default off to run an existing test suite through the classic domain binder; a configured value wins
/**
- * Whether Hibernate's annotation binder binds classes generated from the GORM mapping, instead of the domain
- * binder building Hibernate's boot model by hand. The application's real domain classes are still what is
- * persisted and loaded. Off by default, and intended to become the default.
+ * Whether Hibernate's annotation binder binds classes generated from the GORM mapping (native domain binding),
+ * instead of the classic domain binder building Hibernate's boot model by hand. The application's real domain
+ * classes are still what is persisted and loaded. On by default. {@code false} selects the classic domain
+ * binding, which is deprecated and will be removed.
*/
- boolean generatedDomainClasses = Boolean.getBoolean('grails.hibernate.generatedDomainClasses')
+ boolean generatedDomainClasses = !Boolean.getBoolean('grails.hibernate.classicDomainBinding')
/**
* Cache settings
diff --git a/grails-data-hibernate7/core/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/grails-data-hibernate7/core/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index 3f7709ecd5..f8c04ecacf 100644
--- a/grails-data-hibernate7/core/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/grails-data-hibernate7/core/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -28,6 +28,12 @@
"description": "Whether to enable Hibernate's query cache.",
"defaultValue": false
},
+ {
+ "name": "hibernate.generatedDomainClasses",
+ "type": "java.lang.Boolean",
+ "description": "Whether Hibernate's own annotation binder binds the domain classes (native domain binding). When false, GORM's classic domain binder builds the Hibernate mapping itself; classic domain binding is deprecated and will be removed. See Native Domain Binding in the GORM for Hibernate 7 manual.",
+ "defaultValue": true
+ },
{
"name": "hibernate.grails.proxy.lazy_to_string",
"type": "java.lang.Boolean",
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy
new file mode 100644
index 0000000000..8aef741e79
--- /dev/null
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/ClassicDomainBindingDeprecationSpec.groovy
@@ -0,0 +1,97 @@
+/*
+ * 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 org.grails.orm.hibernate.cfg
+
+import grails.gorm.tests.DomainOne
+import org.grails.datastore.mapping.core.DatastoreUtils
+import org.grails.orm.hibernate.HibernateDatastore
+import org.hibernate.dialect.H2Dialect
+import spock.lang.AutoCleanup
+import spock.lang.Specification
+
+import java.nio.charset.StandardCharsets
+
+/**
+ * Native domain binding is the default. An application that still selects the classic domain binder with
+ * {@code hibernate.generatedDomainClasses: false} boots, and is told once per data source, at startup, that the classic
+ * binding is deprecated and will be removed. The test JVM logs through slf4j-simple, which writes to {@code System.err},
+ * so the warning is read from there. The entity is an existing fixture, so the scanned entity set of the differential
+ * specs is unchanged.
+ */
+class ClassicDomainBindingDeprecationSpec extends Specification {
+
+ private static final String WARNING = 'Classic domain binding is deprecated and will be removed: ' +
+ 'hibernate.generatedDomainClasses is false for data source [default]'
+
+ @AutoCleanup
+ HibernateDatastore datastore
+
+ private String bootAndCaptureLog(Map settings) {
+ PrintStream original = System.err
+ ByteArrayOutputStream captured = new ByteArrayOutputStream()
+ System.setErr(new PrintStream(captured, true, StandardCharsets.UTF_8.name()))
+ try {
+ datastore = new HibernateDatastore(DatastoreUtils.createPropertyResolver([
+ 'dataSource.url' : "jdbc:h2:mem:classicDeprecation${System.nanoTime()};LOCK_TIMEOUT=10000".toString(),
+ 'dataSource.dbCreate' : 'create-drop',
+ 'dataSource.dialect' : H2Dialect.name,
+ 'hibernate.hbm2ddl.auto' : 'create-drop',
+ 'hibernate.cache.queries' : 'false',
+ 'hibernate.cache.use_query_cache': 'false',
+ ] + settings), DomainOne)
+ } finally {
+ System.setErr(original)
+ }
+ return captured.toString(StandardCharsets.UTF_8.name())
+ }
+
+ void "selecting the classic domain binder logs that it is deprecated and will be removed"() {
+ when:
+ String log = bootAndCaptureLog(['hibernate.generatedDomainClasses': false])
+
+ then: 'the warning names the setting and the data source, and the application still works'
+ log.contains('WARN')
+ log.contains(WARNING)
+ log.contains('remove the setting, or set it to true')
+ DomainOne.withTransaction {
+ new DomainOne(controller: 'book', action: 'classic').save(flush: true, failOnError: true)
+ DomainOne.count() == 1
+ }
+ }
+
+ void "the default, native domain binding, starts without the warning"() {
+ when:
+ String log = bootAndCaptureLog([:])
+
+ then:
+ !log.contains(WARNING)
+ DomainOne.withTransaction {
+ new DomainOne(controller: 'book', action: 'native').save(flush: true, failOnError: true)
+ DomainOne.count() == 1
+ }
+ }
+
+ void "selecting native domain binding explicitly starts without the warning"() {
+ when:
+ String log = bootAndCaptureLog(['hibernate.generatedDomainClasses': true])
+
+ then:
+ !log.contains(WARNING)
+ }
+}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfigurationSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfigurationSpec.groovy
index a1a7121530..7dc855dd61 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfigurationSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/HibernateMappingContextConfigurationSpec.groovy
@@ -49,18 +49,18 @@ class HibernateMappingContextConfigurationSpec extends Specification {
config.dataSourceName == 'default'
}
- def "the generated domain classes switch is off by default and can be turned on"() {
+ def "native domain binding is on by default and the classic domain binder can be selected"() {
given:
def config = new HibernateMappingContextConfiguration()
expect:
- !config.generatedDomainClasses
+ config.generatedDomainClasses
when:
- config.setGeneratedDomainClasses(true)
+ config.setGeneratedDomainClasses(false)
then:
- config.generatedDomainClasses
+ !config.generatedDomainClasses
}
def "setBytecodeProvider stores the provider and getGrailsBytecodeProvider returns it"() {
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettingsSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettingsSpec.groovy
index eabd4d8b9d..576e6f50cc 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettingsSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettingsSpec.groovy
@@ -18,6 +18,7 @@
*/
package org.grails.orm.hibernate.connections
+import groovy.json.JsonSlurper
import org.grails.datastore.mapping.core.DatastoreUtils
import org.hibernate.dialect.H2Dialect
import org.springframework.core.io.UrlResource
@@ -118,32 +119,56 @@ class HibernateConnectionSourceSettingsSpec extends Specification {
listeners['create-onflush'].is(onFlushListener)
}
- void "the generated domain classes switch is off by default and can be turned on"() {
+ void "native domain binding is on by default and the classic domain binder can be selected"() {
given:
- String property = 'grails.hibernate.generatedDomainClasses'
+ String property = 'grails.hibernate.classicDomainBinding'
String previous = System.clearProperty(property)
when:
def settings = new HibernateConnectionSourceSettings()
+ then:
+ settings.hibernate.generatedDomainClasses
+
+ when:
+ settings.hibernate.generatedDomainClasses = false
+
then:
!settings.hibernate.generatedDomainClasses
+ cleanup:
+ if (previous != null) {
+ System.setProperty(property, previous)
+ }
+ }
+
+ void "a configured hibernate.generatedDomainClasses value is what the built settings hold"() {
+ given:
+ String property = 'grails.hibernate.classicDomainBinding'
+ String previous = System.clearProperty(property)
+
when:
- settings.hibernate.generatedDomainClasses = true
+ HibernateConnectionSourceSettings settings = new HibernateConnectionSourceSettingsBuilder(
+ DatastoreUtils.createPropertyResolver(['hibernate.generatedDomainClasses': configured])).build()
then:
- settings.hibernate.generatedDomainClasses
+ settings.hibernate.generatedDomainClasses == expected
cleanup:
if (previous != null) {
System.setProperty(property, previous)
}
+
+ where:
+ configured | expected
+ false | false
+ 'false' | false
+ true | true
}
- void "the JVM-wide system property switches the generated domain classes default on, and a configured value wins"() {
+ void "the JVM-wide system property switches the default to the classic domain binder, and a configured value wins"() {
given:
- String property = 'grails.hibernate.generatedDomainClasses'
+ String property = 'grails.hibernate.classicDomainBinding'
String previous = System.getProperty(property)
System.setProperty(property, 'true')
@@ -151,13 +176,13 @@ class HibernateConnectionSourceSettingsSpec extends Specification {
def settings = new HibernateConnectionSourceSettings()
then:
- settings.hibernate.generatedDomainClasses
+ !settings.hibernate.generatedDomainClasses
when:
- settings.hibernate.generatedDomainClasses = false
+ settings.hibernate.generatedDomainClasses = true
then:
- !settings.hibernate.generatedDomainClasses
+ settings.hibernate.generatedDomainClasses
cleanup:
if (previous == null) {
@@ -167,6 +192,25 @@ class HibernateConnectionSourceSettingsSpec extends Specification {
}
}
+ void "the published configuration metadata states the default of hibernate.generatedDomainClasses"() {
+ given: 'the metadata an IDE shows for the key'
+ String previous = System.clearProperty('grails.hibernate.classicDomainBinding')
+ URL metadata = HibernateConnectionSourceSettings.getResource('/META-INF/additional-spring-configuration-metadata.json')
+ Map property = ((List<Map>) ((Map) new JsonSlurper().parse(metadata)).get('properties')).find {
+ it.get('name') == 'hibernate.generatedDomainClasses'
+ }
+
+ expect:
+ property != null
+ property.get('defaultValue') == new HibernateConnectionSourceSettings().hibernate.generatedDomainClasses
+ (property.get('description') as String).contains('deprecated')
+
+ cleanup:
+ if (previous != null) {
+ System.setProperty('grails.hibernate.classicDomainBinding', previous)
+ }
+ }
+
void "test toProperties with dirty checking and custom config"() {
given:
def settings = new HibernateConnectionSourceSettings()
(grails-core) 04/05: docs(hibernate7): native domain binding is the default, classic binding is deprecated
Posted by bo...@apache.org.
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 a58c8763109465071dd9b35051241dfab657b64f
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Fri Oct 9 09:37:13 2026 -0500
docs(hibernate7): native domain binding is the default, classic binding is deprecated
The Native Domain Binding chapter describes native binding as the default
and hibernate.generatedDomainClasses: false as the deprecated fallback that
logs a warning at startup and will be removed; its steps for an existing
database start from the upgraded application and name dbm-gorm-diff, and
the schema table gains the column order of a generated createTable change
set. The configuration reference and the Hibernate 7 migration checklist
state the new default. The 9.0.x upgrade notes say native binding is the
default on upgrade, what to run before upgrading an existing database, how
to fall back temporarily, and link the chapter for the differences. The
module README tells contributors how to run the suite through the classic
binder and what classic-only-specs.txt is.
Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
---
grails-data-hibernate7/README.md | 9 +++++
.../advancedGORMFeatures/nativeDomainBinding.adoc | 29 ++++++++------
.../configuration/configurationReference.adoc | 2 +-
.../asciidoc/gettingStarted/hibernateVersions.adoc | 6 +--
.../src/en/guide/upgrading/upgrading90x.adoc | 44 +++++++++++++---------
5 files changed, 58 insertions(+), 32 deletions(-)
diff --git a/grails-data-hibernate7/README.md b/grails-data-hibernate7/README.md
index dcfea0c232..9484b9f4e7 100644
--- a/grails-data-hibernate7/README.md
+++ b/grails-data-hibernate7/README.md
@@ -53,6 +53,15 @@ Registered via `META-INF/spring/org.springframework.boot.autoconfigure.AutoConfi
A Grails CLI SPI hook (`org.grails.cli.compiler.CompilerAutoConfiguration`) that detects `@Entity` classes in Grails scripts and automatically adds the `grails-data-hibernate7-core` dependency and `grails.gorm.*` imports to the compilation context.
Registered via `META-INF/services/org.grails.cli.compiler.CompilerAutoConfiguration`.
+## Running the suite with the classic domain binder (contributors)
+
+Native domain binding is the default (`hibernate.generatedDomainClasses` defaults to `true`), so the core suite boots every datastore the
+TCK manager builds natively. `./gradlew -Pgrails.test.classicDomainBinding=true :grails-data-hibernate7-core:test` boots them through the
+deprecated classic binder instead (the Gradle property sets the JVM property `grails.hibernate.classicDomainBinding`, which the settings
+default and the TCK manager read; a spec that sets `hibernate.generatedDomainClasses` itself is not affected). The specs listed in
+`core/classic-only-specs.txt` assert facts of the classic boot model and run only in that mode; the default run excludes them. Both modes
+are wired in `gradle/hibernate7-test-config.gradle`.
+
## Differential specs and the frozen classic oracle (contributors)
Native domain binding (`hibernate.generatedDomainClasses`, `GrailsDomainGenerator`) is checked against what the classic domain binder
diff --git a/grails-data-hibernate7/docs/src/docs/asciidoc/advancedGORMFeatures/nativeDomainBinding.adoc b/grails-data-hibernate7/docs/src/docs/asciidoc/advancedGORMFeatures/nativeDomainBinding.adoc
index 578892e224..81f7a6b925 100644
--- a/grails-data-hibernate7/docs/src/docs/asciidoc/advancedGORMFeatures/nativeDomainBinding.adoc
+++ b/grails-data-hibernate7/docs/src/docs/asciidoc/advancedGORMFeatures/nativeDomainBinding.adoc
@@ -22,25 +22,28 @@ under the License.
GORM for Hibernate 7 can bind your domain classes to Hibernate in two ways.
-Classic binding::
-GORM reads your `static mapping` blocks and constraints and builds Hibernate's mapping model itself. This is the default.
-
Native binding::
-GORM describes each domain class with the JPA and Hibernate annotations that express the same mapping, and Hibernate's own annotation binder binds them. Your domain classes are not changed. Sessions, queries, proxies, dirty checking and the instances you work with are still your real domain classes.
+GORM describes each domain class with the JPA and Hibernate annotations that express the same mapping, and Hibernate's own annotation binder binds them. Your domain classes are not changed. Sessions, queries, proxies, dirty checking and the instances you work with are still your real domain classes. This is the default.
+
+Classic binding::
+GORM reads your `static mapping` blocks and constraints and builds Hibernate's mapping model itself. Classic binding is deprecated and will be removed in a later release.
-Native binding is where GORM for Hibernate 7 is heading: the mapping is bound by the same code that binds hand-annotated JPA entities, so it follows Hibernate releases without GORM keeping its own copy of Hibernate's mapping rules. It is opt-in today and is intended to become the default. Classic binding will then be retired.
+Native binding is where GORM for Hibernate 7 is heading: the mapping is bound by the same code that binds hand-annotated JPA entities, so it follows Hibernate releases without GORM keeping its own copy of Hibernate's mapping rules.
-This page lists everything that differs from classic binding, so you can decide when to switch.
+This page lists everything that differs from classic binding, so you know what changes for an application that was built with it.
+[[nativeDomainBinding-enabling]]
=== Enabling Native Binding
-Set `hibernate.generatedDomainClasses` to `true`. It is a boolean and defaults to `false`.
+Native binding is on by default: `hibernate.generatedDomainClasses` is a boolean and defaults to `true`. Nothing needs to be set.
+
+Setting it to `false` selects the deprecated classic binding. Use this only to keep an existing application running while you work through the differences on this page; the application logs a warning at startup that names the setting, and the option goes away when classic binding is removed.
[source,yaml]
.grails-app/conf/application.yml
----
hibernate:
- generatedDomainClasses: true
+ generatedDomainClasses: false # deprecated: selects the classic binding
----
The same key works wherever the configuration is read: `application.yml` in Spring Boot, or the `Map` or `PropertyResolver` passed to `HibernateDatastore` when GORM is used standalone. The setting applies to every data source of the application.
@@ -312,6 +315,10 @@ The schema of 765 groups of related domain classes was created with both binding
| No index named after a closure on the table of a collection whose `index` is a closure.
| See <<nativeDomainBinding-behavior,Differences in Behavior>>.
| A database created by classic binding has an index with a name that depends on the start it was created in. Drop it if you want to be rid of it.
+
+| The order of the columns in a `createTable` change set that `dbm-generate-gorm-changelog` or `dbm-gorm-diff` writes: the identifier, then the other columns in the order of the property names (the `version` column among them), then the foreign key columns.
+| Hibernate's annotation binder binds the properties of a class sorted by name, and the migration commands read the mapping model as it was bound. Classic binding listed the identifier, the version, then the properties in declaration order. The schema that `dbCreate` creates is not affected: Hibernate orders the columns of a table it creates itself, in the same way for both bindings, which is why the comparison above lists no other difference in column order.
+| None. Liquibase does not compare the order of columns, so a diff against an existing database reports nothing. A table created from a new change set has its columns in the new order.
|===
The comparison finds no difference in the unique keys, indexes and identifier columns that natural ids, `unique` groups and `index` options create: they have the same columns in the same order as with classic binding.
@@ -320,10 +327,10 @@ The comparison finds no difference in the unique keys, indexes and identifier co
Do not switch a production database over blindly. Whether `dbCreate: update` or a Liquibase changelog would change anything depends on the differences above.
-. Start the application with `hibernate.generatedDomainClasses: true` against a copy of your schema. Fix every refused mapping from the table above; classic binding cannot use these either.
+. Start the upgraded application, with its default native binding, against a copy of your schema. Fix every refused mapping from the table above; classic binding cannot use these either.
. Run <<ref-diff-scripts-dbm-gorm-diff,dbm-gorm-diff>> against the copy. An empty diff means the switch does not change the schema. Otherwise, compare each reported change with the table above, and apply the changes you want through a migration.
-. Run your test suite once with the setting on.
-. Set the property in the environment where you want it first, for example in `development` only.
+. Run your test suite once with native binding.
+. If you need more time, set `hibernate.generatedDomainClasses: false` in the environments that are not ready yet, for example in `production` only, and remove it as soon as the migration has run. Classic binding is deprecated and will be removed.
Prefer migrations over `dbCreate: update` for a production schema.
diff --git a/grails-data-hibernate7/docs/src/docs/asciidoc/configuration/configurationReference.adoc b/grails-data-hibernate7/docs/src/docs/asciidoc/configuration/configurationReference.adoc
index 2a0aa39d51..6fd360d59b 100644
--- a/grails-data-hibernate7/docs/src/docs/asciidoc/configuration/configurationReference.adoc
+++ b/grails-data-hibernate7/docs/src/docs/asciidoc/configuration/configurationReference.adoc
@@ -61,7 +61,7 @@ name,description,default value
`hibernate.configLocations`, Location of additional Hibernate XML configuration files
`hibernate.packagesToScan`, Specify packages to search for autodetection of your entity classes in the classpath
`hibernate.grails.proxy.lazy_to_string`, Whether `toString()` on an uninitialized proxy avoids initializing it (see Proxies and toString()), `false`
-`hibernate.generatedDomainClasses`, Whether Hibernate's own annotation binder binds the domain classes (see Native Domain Binding), `false`
+`hibernate.generatedDomainClasses`, Whether Hibernate's own annotation binder binds the domain classes (see Native Domain Binding); `false` selects the deprecated classic binding, `true`
|===
In addition, any additional settings that start with `hibernate.` are passed through to Hibernate, so if there is any specific feature of Hibernate you wish to configure that is possible.
diff --git a/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc b/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
index 101f5eac78..1a6b4cc25d 100644
--- a/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
+++ b/grails-data-hibernate7/docs/src/docs/asciidoc/gettingStarted/hibernateVersions.adoc
@@ -113,9 +113,9 @@ If you are migrating an application from Hibernate 5 or the Grails Hibernate 5 p
| `insertable: false` and `updatable: false` are honored, enum columns receive the `comment`, `defaultValue`, `read` and `write` of their column mapping, the elements of basic-value collections of an owner with several unidirectional collections are stored, and the inverse side of a many-to-many reads the join table that its owner writes.
| Review domain classes that use `insertable: false` or `updatable: false`, because values that used to be written are no longer written. Compare the generated schema of enum properties with your database before using `dbCreate=update`. See <<nativeDomainBinding,Native Domain Binding>> for the related schema differences.
-| Native domain binding (opt-in)
-| `hibernate.generatedDomainClasses: true` makes Hibernate's own annotation binder bind the domain classes. It is off by default and is intended to become the default. A few mapping options are refused at startup and the generated schema differs from classic binding in documented cases.
-| Before enabling it, fix the mappings listed in <<nativeDomainBinding-refused,Mappings Native Binding Refuses>> and run `dbm-gorm-diff` against a copy of the existing database. See <<nativeDomainBinding-schema,Differences in the Schema>>.
+| Native domain binding (the default)
+| Hibernate's own annotation binder binds the domain classes; `hibernate.generatedDomainClasses` defaults to `true`. A few mapping options that classic binding could not use either are refused at startup, and the generated schema differs from classic binding in documented cases. `hibernate.generatedDomainClasses: false` selects the classic binding, which is deprecated, logs a warning at startup and will be removed.
+| Before upgrading an existing database, fix the mappings listed in <<nativeDomainBinding-refused,Mappings Native Binding Refuses>> and run `dbm-gorm-diff` against a copy of the database with the upgraded application. See <<nativeDomainBinding-schema,Differences in the Schema>> and <<nativeDomainBinding-enabling,Enabling Native Binding>> for the temporary fallback.
| Query locks and query cache
| Locked queries are not query-cacheable.
diff --git a/grails-doc/src/en/guide/upgrading/upgrading90x.adoc b/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
index fcdd18e161..5c913f88e2 100644
--- a/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
+++ b/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
@@ -57,7 +57,7 @@ class Author {
The same applies to a many-to-many from a class to itself: `belongsTo` names the class itself.
A unidirectional many-to-many, a many-to-many that has `belongsTo` on either side, and one where either side is a `Map` need no change.
-The rule is the same whether or not you enable native domain binding, see below.
+The rule is the same with native domain binding, the default, and with the deprecated classic binding, see below.
See link:{hibernate7Guide}index.html#gormAssociation-manyToMany[Many-to-Many Associations] in the GORM for Hibernate 7 manual.
@@ -81,19 +81,9 @@ They are also fixed in the 8.0.x line, so an application that is already on a re
===== 1.3 Native Domain Binding
-GORM for Hibernate 7 can bind your domain classes with Hibernate's own annotation binder instead of building Hibernate's mapping itself.
-This is native domain binding.
-It is the direction GORM for Hibernate 7 is taking and is intended to become the default.
-In Grails {version} it is opt-in and the default stays classic binding.
-
-Enable it with the `hibernate.generatedDomainClasses` setting:
-
-[source,yaml]
-.grails-app/conf/application.yml
-----
-hibernate:
- generatedDomainClasses: true
-----
+GORM for Hibernate 7 binds your domain classes with Hibernate's own annotation binder instead of building Hibernate's mapping itself.
+This is native domain binding, and in Grails {version} it is the default: an upgraded application starts with it without any setting.
+The classic binding of earlier releases is deprecated and will be removed in a later release.
Your domain classes, your queries and the GORM API do not change.
The mapping can, though:
@@ -108,8 +98,28 @@ The mapping can, though:
Classic binding shares one table whose foreign key points at only one owner, so the collection of any other owner cannot be stored, and it does not start when the properties have the same name.
The first owner (by entity name, then property path) keeps the table and the key column it has today, the others get names that start with their table and the path of the embedded property.
* A custom collection type on a `hasMany` now takes effect, see <<native-binding-custom-collection-type,1.4>>.
+* A `createTable` change set written by `dbm-generate-gorm-changelog` or `dbm-gorm-diff` lists the columns in a different order: the identifier, then the columns in the order of the property names, then the foreign keys.
+ A diff against an existing database does not report this, because Liquibase does not compare column order.
+
+Before you upgrade an application with an existing database:
+
+. Start the upgraded application against a copy of the database and fix every refused mapping; the startup error says what to change.
+. Run `dbm-gorm-diff` against the copy with the upgraded application, which uses the new default.
+ An empty diff means the switch does not change your schema.
+ Otherwise, compare each reported change with the schema differences in the manual and apply the ones you want through a migration.
+. Run your test suite once.
+
+If you need more time, the `hibernate.generatedDomainClasses` setting selects the classic binding for the environments that are not ready yet:
+
+[source,yaml]
+.grails-app/conf/application.yml
+----
+hibernate:
+ generatedDomainClasses: false # deprecated: selects the classic binding
+----
-Before you switch an existing database, run `dbm-gorm-diff` against a copy of it with the setting on.
+The application then logs a warning at startup that names the setting.
+Remove the setting as soon as the migration has run, because classic binding will be removed.
The link:{hibernate7Guide}index.html#advancedGORMFeatures-nativeDomainBinding[Native Domain Binding] chapter of the GORM for Hibernate 7 manual lists every refused mapping, every schema difference and what each means for an existing database.
@@ -135,9 +145,9 @@ Native binding applies the type.
Hibernate creates, wraps and loads the collection with your class, so the code of your collection type runs where it never ran before.
The schema is the same.
-If your application maps a custom collection type, test it with `hibernate.generatedDomainClasses` set to `true` before you switch.
+If your application maps a custom collection type, test it with the upgraded application before you deploy.
A type that was never exercised can fail or behave differently once it is used.
-With classic binding, which stays the default in Grails {version}, nothing changes.
+With the deprecated classic binding (`hibernate.generatedDomainClasses: false`) nothing changes.
A custom collection type on a `hasMany` of basic values is not supported by either binding.
(grails-core) 02/05: test(hibernate7): run the suite natively by default and the classic binder on demand
Posted by bo...@apache.org.
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 3ad3e575ffec470adb29d229c49f1bce224283e8
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Thu Oct 8 22:11:35 2026 -0500
test(hibernate7): run the suite natively by default and the classic binder on demand
With native binding the default, the core suite boots every manager-built
datastore natively unless -Pgrails.test.classicDomainBinding=true sets the
inverted JVM property, which the TCK manager and the settings default read.
generated-mode-exclusions.txt becomes classic-only-specs.txt with the
opposite meaning: the default run excludes the listed specs, the classic
run runs everything. Every binder-internals spec on the old list was run
against a natively bound datastore; ten pass (the generator differential
among them, so it now runs in the default mode) and are no longer listed.
The six that remain assert facts of the classic boot model or pin classic
defects with @PendingFeature.
Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
---
gradle/hibernate7-test-config.gradle | 20 +++++-----
grails-data-hibernate7/core/classic-only-specs.txt | 40 ++++++++++++++++++++
.../core/generated-mode-exclusions.txt | 43 ----------------------
.../gorm/tests/HibernateGormDatastoreSpec.groovy | 6 ++-
.../core/GrailsDataHibernate7TckManager.groovy | 21 +++++------
5 files changed, 65 insertions(+), 65 deletions(-)
diff --git a/gradle/hibernate7-test-config.gradle b/gradle/hibernate7-test-config.gradle
index c43f56e8dc..25ea89a0b2 100644
--- a/gradle/hibernate7-test-config.gradle
+++ b/gradle/hibernate7-test-config.gradle
@@ -46,15 +46,17 @@ tasks.withType(Test).configureEach {
useJUnitPlatform()
- // Opt-in: -Pgrails.test.generatedDomainClasses=true runs the suite with every manager-built datastore booted through the
- // generated-domain-class path (hibernate.generatedDomainClasses). Binder mode stays the default. Specs that exercise the
- // domain binder's internals do not apply to that path and are listed, one class name per line, in the module's
- // generated-mode-exclusions.txt.
- if (providers.gradleProperty('grails.test.generatedDomainClasses').map { it.toBoolean() }.getOrElse(false)) {
- systemProperty('grails.hibernate.generatedDomainClasses', 'true')
- File exclusions = project.file('generated-mode-exclusions.txt')
- if (exclusions.exists()) {
- exclusions.readLines().collect { it.trim() }.findAll { it && !it.startsWith('#') }.each { String pattern ->
+ // Native domain binding (hibernate.generatedDomainClasses, on by default) is what the suite runs by default.
+ // -Pgrails.test.classicDomainBinding=true boots every datastore that does not set the key itself through the classic
+ // domain binder instead (system property grails.hibernate.classicDomainBinding, read by the settings default and by the
+ // TCK manager). Specs that exercise the classic binder's internals only make sense in that run and are listed, one
+ // class name per line, in the module's classic-only-specs.txt: the default run excludes them, the classic run runs them.
+ if (providers.gradleProperty('grails.test.classicDomainBinding').map { it.toBoolean() }.getOrElse(false)) {
+ systemProperty('grails.hibernate.classicDomainBinding', 'true')
+ } else {
+ File classicOnly = project.file('classic-only-specs.txt')
+ if (classicOnly.exists()) {
+ classicOnly.readLines().collect { it.trim() }.findAll { it && !it.startsWith('#') }.each { String pattern ->
filter.excludeTestsMatching(pattern)
}
}
diff --git a/grails-data-hibernate7/core/classic-only-specs.txt b/grails-data-hibernate7/core/classic-only-specs.txt
new file mode 100644
index 0000000000..f2b041d674
--- /dev/null
+++ b/grails-data-hibernate7/core/classic-only-specs.txt
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+# Specs that run only when the whole suite boots through the classic domain binder:
+# ./gradlew -Pgrails.test.classicDomainBinding=true :grails-data-hibernate7-core:test
+#
+# The default run boots every manager-built datastore through native domain binding (hibernate.generatedDomainClasses,
+# on by default) and EXCLUDES the specs listed here; the classic run runs every spec and does not read this file.
+#
+# They exercise the classic domain binder or the generator themselves against the classic datastore of the base spec
+# (they build binder objects by hand, bind through createPersistentEntity / hibernateFirstPass, or compare the binder
+# with the generator), so they need the classic binder to be the one that booted the datastore. A spec is a "binder
+# internals" spec when its source lives under cfg/domainbinding or mentions GrailsDomainBinder, GrailsDomainGenerator,
+# GeneratedDomainClassBinder, hibernateFirstPass, createPersistentEntity, getGrailsDomainBinder, getCollector(,
+# InFlightMetadataCollector or MetadataBuildingContext. Only those that FAIL with a natively bound datastore are listed,
+# one fully qualified class name per line; the others run and pass in both modes (every other binder-internals spec,
+# the generator differential included, was run against a natively bound datastore before being left out of this list).
+# The six listed assert facts of the classic boot model (a collection table the classic binder creates, a unique key it
+# drops, the type parameters it sets) or pin classic defects with @PendingFeature, which native binding does not have,
+# so they only hold against a classic datastore. The list goes away with the classic binder.
+#
+org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateBasicPropertySpec
+org.grails.orm.hibernate.cfg.domainbinding.jpa.EntityCollectionKeyDefectSpec
+org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainBinderEmbeddedCollectionDefectSpec
+org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainBinderOptionDefectSpec
+org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorSpec
+org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorUniqueGroupSpec
diff --git a/grails-data-hibernate7/core/generated-mode-exclusions.txt b/grails-data-hibernate7/core/generated-mode-exclusions.txt
deleted file mode 100644
index 47bf461ab5..0000000000
--- a/grails-data-hibernate7/core/generated-mode-exclusions.txt
+++ /dev/null
@@ -1,43 +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.
-#
-# Specs that do not apply when the whole suite runs through the generated domain classes:
-# ./gradlew -Pgrails.test.generatedDomainClasses=true :grails-data-hibernate7-core:test
-#
-# They exercise the domain binder or the generator themselves (they build binder objects by hand, bind through
-# createPersistentEntity / hibernateFirstPass, or compare the binder with the generator), so their subject is not the path
-# the switch selects. A spec is a "binder internals" spec when its source lives under cfg/domainbinding or mentions
-# GrailsDomainBinder, GrailsDomainGenerator, GeneratedDomainClassBinder, hibernateFirstPass, createPersistentEntity,
-# getGrailsDomainBinder, getCollector(, InFlightMetadataCollector or MetadataBuildingContext (145 source files today).
-# Only those that FAIL in generated mode are listed, one fully qualified class name per line; the others run and pass.
-# Binder mode (the default) runs every spec and does not read this file.
-#
-org.grails.orm.hibernate.cfg.domainbinding.GrailsPropertyBinderSpec
-org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateBasicPropertySpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.EntityCollectionKeyDefectSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainBinderEmbeddedCollectionDefectSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainBinderOptionDefectSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorDifferentialSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorIndexSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorNaturalIdSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorTenantSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.GrailsDomainGeneratorUniqueGroupSpec
-org.grails.orm.hibernate.cfg.domainbinding.jpa.ManyToManyOwnershipDefectSpec
-org.grails.orm.hibernate.cfg.domainbinding.secondpass.CollectionKeyBinderSpec
-org.grails.orm.hibernate.cfg.domainbinding.secondpass.ManyToOneElementBinderSpec
-org.grails.orm.hibernate.cfg.domainbinding.secondpass.MapSecondPassBinderSpec
-org.grails.orm.hibernate.cfg.domainbinding.secondpass.ToManyEntityMultiTenantFilterBinderSpec
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateGormDatastoreSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateGormDatastoreSpec.groovy
index 8710185103..382f2257dd 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateGormDatastoreSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateGormDatastoreSpec.groovy
@@ -72,8 +72,10 @@ class HibernateGormDatastoreSpec extends GrailsDataTckSpec<GrailsDataHibernate7T
/**
* Registers the domain classes like {@code manager.registerDomainClasses(...)}, and boots the datastore through the
- * generated-domain-class path ({@code hibernate.generatedDomainClasses}): Hibernate's annotation binder binds classes
- * generated from the GORM mapping while sessions keep persisting and loading the real domain classes.
+ * generated-domain-class path ({@code hibernate.generatedDomainClasses}) whatever mode the suite runs in: Hibernate's
+ * annotation binder binds classes generated from the GORM mapping while sessions keep persisting and loading the real
+ * domain classes. {@code registerDomainClasses} boots through the mode of the suite, native by default and the classic
+ * domain binder with {@code -Pgrails.test.classicDomainBinding=true}.
*/
void registerGeneratedDomainClasses(Class... classes) {
manager.registerGeneratedDomainClasses(classes)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/apache/grails/data/hibernate7/core/GrailsDataHibernate7TckManager.groovy b/grails-data-hibernate7/core/src/test/groovy/org/apache/grails/data/hibernate7/core/GrailsDataHibernate7TckManager.groovy
index b8912d7c25..6edf0bda0c 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/apache/grails/data/hibernate7/core/GrailsDataHibernate7TckManager.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/apache/grails/data/hibernate7/core/GrailsDataHibernate7TckManager.groovy
@@ -57,21 +57,22 @@ class GrailsDataHibernate7TckManager extends GrailsDataTckManager {
boolean isTransactional = true
/**
- * System property that boots every datastore through the generated-domain-class path
- * ({@code hibernate.generatedDomainClasses}). It is off by default; the Gradle property
- * {@code -Pgrails.test.generatedDomainClasses=true} sets it on the test JVM, which runs the whole module suite in
- * generated mode. The datastores this manager builds read it, and so does the default of
+ * System property that boots every datastore through the classic domain binder
+ * ({@code hibernate.generatedDomainClasses: false}). Native domain binding is the default; the Gradle property
+ * {@code -Pgrails.test.classicDomainBinding=true} sets this property on the test JVM, which runs the whole module suite
+ * in classic mode. The datastores this manager builds read it, and so does the default of
* {@code HibernateConnectionSourceSettings}, which covers the specs that build their own {@code HibernateDatastore}
* without setting {@code hibernate.generatedDomainClasses} themselves.
*/
- static final String GENERATED_MODE_PROPERTY = 'grails.hibernate.generatedDomainClasses'
+ static final String CLASSIC_MODE_PROPERTY = 'grails.hibernate.classicDomainBinding'
- boolean generatedDomainClasses = Boolean.getBoolean(GENERATED_MODE_PROPERTY)
+ boolean generatedDomainClasses = !Boolean.getBoolean(CLASSIC_MODE_PROPERTY)
/**
* Registers the classes like {@link #registerDomainClasses} and boots the datastore through the generated-domain-class
- * path: Hibernate's annotation binder binds classes generated from the GORM mapping, and the real domain classes are what
- * sessions persist and load. {@code registerDomainClasses} is unchanged and keeps booting through the domain binder.
+ * path whatever mode the suite runs in: Hibernate's annotation binder binds classes generated from the GORM mapping,
+ * and the real domain classes are what sessions persist and load. {@code registerDomainClasses} boots through the
+ * mode of the suite: native by default, the classic domain binder with {@link #CLASSIC_MODE_PROPERTY}.
*/
void registerGeneratedDomainClasses(Class... classes) {
generatedDomainClasses = true
@@ -89,9 +90,7 @@ class GrailsDataHibernate7TckManager extends GrailsDataTckManager {
grailsApplication = new DefaultGrailsApplication(domainClasses as Class[], new GroovyClassLoader(GrailsDataHibernate7TckManager.getClassLoader()))
grailsConfig.dataSource.dbCreate = "create-drop"
grailsConfig.hibernate.proxy_factory_class = "org.grails.orm.hibernate.proxy.ByteBuddyGroovyProxyFactory"
- if (generatedDomainClasses) {
- grailsConfig.hibernate.generatedDomainClasses = true
- }
+ grailsConfig.hibernate.generatedDomainClasses = generatedDomainClasses
grailsConfig.'grails.gorm.default.mapping' = {
id generator: 'identity'
}