jdaugherty opened a new pull request, #16471:
URL: https://github.com/apache/grails-core/pull/16471
Fixes #16465
### Problem
A table-per-hierarchy tree without a discriminator mapping behaved
differently in `grails-data-hibernate7` than in `grails-data-hibernate5`:
- The discriminator column was named `DTYPE` instead of `class`. A table
created by `grails-data-hibernate5` then failed `dbCreate: 'validate'` with
`missing column [DTYPE]`.
- Subclasses stored their simple name (`Car`) instead of the fully qualified
name (`example.Car`), so existing rows did not match.
- A root mapping that set only the column (`discriminator column: 'class'`)
failed at startup with `Could not parse discriminator value 'null'`.
The Hibernate 7 docs already describe a `class` column, and the `DTYPE`
default dates from the initial Hibernate 7 port, so this restores the intended
default rather than adding a setting.
### Changes
- The default discriminator column is named `class`
(`GrailsDomainBinder.DEFAULT_DISCRIMINATOR_COLUMN_NAME`, which replaces
`JPA_DEFAULT_DISCRIMINATOR_TYPE`). Hibernate 7 no longer provides
`RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME`.
- A subclass without a discriminator value stores its fully qualified class
name.
- A root mapping that sets only the discriminator column or formula keeps
the class name as the root value.
- The inheritance docs state the default column and values.
### Tests
- New `TablePerHierarchyDefaultDiscriminatorSpec`, through the public GORM
API:
- a three-level hierarchy stores fully qualified names in a `class` column
and loads polymorphically;
- `dbCreate: 'validate'` succeeds against a hand-built
`grails-data-hibernate5`-style table, and its existing rows load as the right
classes;
- a column-only root mapping keeps fully qualified values.
On the current 8.0.x code, the spec fails with both errors from the issue.
- The binder and entity specs are updated to the new defaults, with new
cases for column-only and formula-only mappings and the subclass default.
- `grails-data-hibernate7-core`, `-dbmigration` and `-dbmigration-core`
tests pass, and CodeNarc and Checkstyle are clean.
### Related
#16470 fixes a separate bug in the same area: a query on an intermediate
class (`Car`) misses its subclasses' rows (`SportsCar`). The hierarchy in
#16465 has that shape, so an application needs both fixes to read its existing
data fully. This PR doesn't overlap with #16470's files.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]