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 be9a58b4aa576a878705d83a4db378f834fae9d5 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Thu Oct 8 14:14:03 2026 -0500 docs: document that a custom collection type takes effect with native binding Classic binding accepts a custom collection type on a hasMany of domain classes but never uses the class. Native binding applies it, so the upgrade notes now say so in a section of their own (1.4), the manual lists it under the differences in behavior instead of under what stays the same, and the stale examples of refused mappings in section 1.3 (an index on a collection property, a natural id on a subclass, a collection inside an embedded class, a Map on a many-to-many) are removed because native binding accepts all of them now. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- .../advancedGORMFeatures/nativeDomainBinding.adoc | 4 ++- .../src/en/guide/upgrading/upgrading90x.adoc | 31 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) 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 657c068079..edec11f96a 100644 --- a/grails-data-hibernate7/docs/src/docs/asciidoc/advancedGORMFeatures/nativeDomainBinding.adoc +++ b/grails-data-hibernate7/docs/src/docs/asciidoc/advancedGORMFeatures/nativeDomainBinding.adoc @@ -66,7 +66,6 @@ For the domain classes in GORM's own test suites, both bindings produce the same * `params` on a registered type name such as `type: 'string'` are ignored, as with classic binding. They reach the type when it is a `UserType` that implements `ParameterizedType`. * A `type` that names an `AttributeConverter` class, for example `type: 'org.hibernate.type.YesNoConverter'`, converts the property with it, on a single property as well as on a `hasMany` stored in one column, as with classic binding. * A registered type name for a different Java type than the property's, for example `type: 'string'` on an `Integer`, gives the column of the registered type (`varchar(255)`), as with classic binding. Neither binding converts the value, so saving a value that is not null fails with a `ClassCastException` in both; a null value and the other properties of the class are stored. -* A custom collection type (a `UserCollectionType` class) as the `type` of a `hasMany` of domain classes is applied to the collection. Classic binding boots with the same schema but never uses the class: it keeps Hibernate's own collection. * A natural id (`id natural: [...]`) may name an embedded object (the unique key spans its columns, in the order of the embedded class), and a name that is no property of the class is skipped without a message, as with classic binding. * A natural id declared on a subclass adds a unique key to the table of the hierarchy (the table of the subclass in a joined hierarchy), over the columns of the named properties in the order the mapping names them, and makes those properties updatable only when the natural id is `mutable`. Classic binding also marks the properties as natural identifiers, and with Hibernate 7 that makes every load of the subclass entity fail with a `NullPointerException`; native binding does not mark them [...] * Identifier generators, inheritance strategies (single table, joined and table-per-concrete-class), discriminators, natural ids, optimistic locking, lazy and eager fetching, cascades, sorting, batch size and `cache` usage are mapped as with classic binding. @@ -133,6 +132,9 @@ Some bugs of classic binding are not copied by native binding. Native binding do | Mapping | Difference +| A custom collection type (a `UserCollectionType` class) as the `type` of a `hasMany` of domain classes, for example `books type: MyCollectionType`. +| Classic binding boots with the same schema but never uses the class: it keeps Hibernate's own collection and does not even create an instance of your type. Native binding applies the type, so Hibernate creates, wraps and loads the collection with your class. If you map a custom collection type that has never been exercised, test it before you switch. On a `hasMany` of basic values neither binding supports it. + | A `unique` group that includes an enum property. | Classic binding drops the group. Native binding creates the unique constraint. With `dbCreate: update` the constraint is added to an existing table, and fails if the table holds duplicates. diff --git a/grails-doc/src/en/guide/upgrading/upgrading90x.adoc b/grails-doc/src/en/guide/upgrading/upgrading90x.adoc index c71f707736..9f3d83ff6d 100644 --- a/grails-doc/src/en/guide/upgrading/upgrading90x.adoc +++ b/grails-doc/src/en/guide/upgrading/upgrading90x.adoc @@ -100,10 +100,39 @@ The mapping can, though: * A few mapping options cannot be expressed with annotations. Native binding refuses such a mapping with an `UnsupportedOperationException` at startup instead of ignoring the option. - Examples are an `index` or a `unique` group on a collection property, a natural id on a subclass, a collection inside an embedded class, and a `Map` on a many-to-many. + The manual chapter lists them. * The generated schema differs from the one of classic binding in a few documented cases, for example a `check (idx >= 0)` constraint on the index column of every list, and the column types of foreign keys to nested composite identifiers. * A few defects of classic binding are not copied, such as a `unique` group that includes an enum property being dropped. +* A custom collection type on a `hasMany` now takes effect, see <<native-binding-custom-collection-type,1.4>>. Before you switch an existing database, run `dbm-gorm-diff` against a copy of it with the setting on. 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. + +[[native-binding-custom-collection-type]] +===== 1.4 Custom Collection Types Take Effect with Native Binding + +A `hasMany` of domain classes can name a Hibernate `UserCollectionType` as its `type`: + +[source,groovy] +---- +class Author { + static hasMany = [books: Book] + static mapping = { + books type: MyCollectionType + } +} +---- + +Classic binding accepts this mapping and creates the usual schema, but it never uses the class. +It does not even create an instance of `MyCollectionType`, and `author.books` is an ordinary Hibernate collection. + +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. +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. + +A custom collection type on a `hasMany` of basic values is not supported by either binding.
