Repository navigation
Description
Summary
Add a small set of application-level scenario specs under grails-test-examples (Hibernate 5 and Hibernate 7 examples) that run one query through each entry point the module-level join tests do not reach, with an association path next to an alias or a left join. About ten scenarios, run on both versions, with the expected rows written out in each spec.
Background
Alias, association-block and join-type bugs in criteria queries were reported and fixed one combination at a time (#16762, #16773, #16866, #16889, tracked in #16896). Each review round found the next combination, because the specs held hand-picked examples.
#16773 changed that at module level. AliasPathModelSpec (grails-data-hibernate7/core, grails.gorm.tests) checks every combination of aliases, association blocks, dotted paths, junctions and every property criterion against one stated rule: a criteria joins each association path of the query once, an inner join unless every declaration of the path asks for a left join. It runs the combinations as a query, as a detached criteria and as a subquery, against a real H2 database with real mapped domain classes, and compares the rows with a reference model that is written out in the spec. It is an integration test, not mocked.
The gap
The module spec reaches the translator through withCriteria, DetachedCriteria and in with a subquery. Applications also reach it through entry points that build their own criteria, and through wiring that exists only in an application:
| Entry point | What it builds | Why the module spec does not reach it |
|---|---|---|
where { } DSL |
a DetachedCriteria from compile-time transformed closures: association criteria and dotted names |
the closure is transformed when the class is compiled; the spec builds criteria with method calls |
Dynamic finders (findAllBy...) |
criteria from the method name, with association paths | built by the finder machinery, not by the builder |
Data service @Where (see #16835) |
a where query compiled into a service method |
a different compile-time path |
list(fetch: ...) and HQL |
fetch joins and HQL, not criteria | separate builders; see #16898 |
| Multiple data sources, multi-tenancy | the same criteria on a named connection or with a tenant restriction | needs more than one datastore |
| Domain classes compiled as Grails artefacts | AST-enhanced static API | the spec registers plain @Entity classes |
None of these is known to be broken. The point is that nothing would tell us.
Scope
Add specs to the existing integration-test modules, not new modules:
- H7:
grails-test-examples/hibernate7/gorm(GormCriteriaQueriesSpecand the where-query services),hibernate7/grails-data-service,hibernate7/grails-multiple-datasources - H5:
grails-test-examples/hibernate5/grails-hibernate,hibernate5/grails-data-service,hibernate5/grails-multiple-datasources
Each scenario is one query with the rows it must return, written in the spec. Both versions run the same expectation where the behaviour is the same (see #16889 for the decided differences, where H5's results depend on the order of the steps; those scenarios get an H5 expectation and an H7 one with a comment).
Scenarios (domain: a root with a to-one association that has a collection that has a to-one, as the module spec's Club -> Team -> Like -> Tag):
where { }with an association path and a second restriction on the same path: one join, one element satisfies both.where { }withorover two association paths: a row without one of the associations is dropped (inner), as for the criteria builder.- Dynamic finder through an association path next to
createAliasin awithCriteriaon the same class: same rows as the equivalent criteria. - Data service
@Whereon an association path with an aggregate on the right (Run an aggregate on the right of a data service @Where comparison as a subquery #16835). - A
wherequery with a subquery that correlates through an association ({alias}and an outer alias). not { }over a left-joined null: a missing association matchesne, does not matchnot { eq }(SQL three-valued logic,neisx <> v or x is nullas on H5).- A named connection: the same association query on the second data source returns the rows of that data source.
- A multi-tenant domain: the tenant restriction and an association path together.
isNull/isNotNullon an association through a left alias.list(fetch: [assoc: 'join'])with a null association keeps the row (Hibernate 7: the fetch mode join of list() keeps the instances whose association is null or empty #16898), to keep the fetch and the criteria paths consistent.
Acceptance criteria
- Each scenario is one feature in an existing Spock spec, runs on the H5 and H7 examples, and names the rows it expects.
- No scenario duplicates a combination
AliasPathModelSpecalready checks; each one stands for an entry point. - A scenario that exposes a difference between the entry point and the criteria builder gets its own issue; this issue does not fix them.
- No change to production code.
Not in scope
- A combinatorial run at application level. The module spec does that and takes minutes; the application layer is for entry points, not combinations.
- A model for H5. Its results depend on the order of the steps, so one rule cannot match it (Hibernate 7: do repeated blocks of one association share a join, or does each block get its own? #16889).
- Changing the
Query.Criterionhierarchy (Query.Criterion: no operation to read a criterion, three subquery shapes, duplicate state #16900).
How to run
./gradlew :grails-test-examples-hibernate7-gorm:integrationTest
./gradlew :grails-test-examples-hibernate5-grails-hibernate:integrationTest
(project paths as in each module's build.gradle; add the multi-datasource and data-service modules the same way).
Related
#16762, #16773, #16866, #16889, #16896 (alias tracking), #16835, #16898, #16900
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
borinquenkid commentedon Nov 9, 2026
Written in #16907, stacked on #16773: all ten scenarios, H7 and H5, no production code. Three differences came out of them: #16905 (H5: where through one collection path twice throws;
nethrough a left alias drops a null association), #16906 (H7: a where query started from a named connection finds no session) and #16853 (H5 fetch join, already open). Each is a pending feature in the specs.Merge pull request #16907 from apache/test/app-level-query-scenarios-…
borinquenkid commentedon Nov 12, 2026
Done in #16907 (merged to 8.0.x): the ten entry-point scenarios run on the Hibernate 7 and Hibernate 5 examples. The differences they found are tracked separately in #16905 (H5/H7 results), #16906 (named connection on H7) and #16898/#16853 (
list(fetch: join)).