jdaugherty opened a new pull request, #16470:
URL: https://github.com/apache/grails-core/pull/16470
Fixes #16464
## Problem
In a Hibernate 7 inheritance tree with three or more levels (`Vehicle` →
`Car` → `SportsCar` / `Sedan`), queries on the intermediate class ignore the
rows of its subclasses. `Car.count()`, `Car.list()`, criteria, dynamic finders
and HQL return only the `Car` rows.
`RootBinder` added every subclass in the tree to the root `RootClass`.
Hibernate finds a class's subclasses through its direct superclass
(`PersistentClass.getSubclasses()` recurses through each class's direct
subclasses), so the intermediate class had no subclasses in the mapping model.
## Fix
Each subclass is now added to its own superclass. The root still sees the
whole tree through Hibernate's recursion, with no duplicates. Hibernate 5
already binds subclasses this way (`parent.addSubclass(subClass)` in
`GrailsDomainBinder`).
## Tests
- `IntermediateSubclassQuerySpec` covers all three inheritance strategies
(table-per-hierarchy, joined, table-per-concrete-class):
- queries on the intermediate class: `count()`, `list()`, HQL count,
criteria, dynamic finder
- loading a subclass row by id through the intermediate class returns the
subclass instance
- root and leaf queries are unchanged
- `RootBinderSpec` checks that the direct subclasses of the root and of the
intermediate class are correct, and that the root sees each subclass once.
Without the fix, 6 of the new tests fail. With the joined strategy, queries
on the intermediate class already worked before the fix, but loading by id
through the intermediate class failed for all three strategies.
--
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]