Skip to content

Application-level scenario specs for the query entry points the module join tests do not reach #16902

Closed

Description

@borinquenkid

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 (GormCriteriaQueriesSpec and 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):

  1. where { } with an association path and a second restriction on the same path: one join, one element satisfies both.
  2. where { } with or over two association paths: a row without one of the associations is dropped (inner), as for the criteria builder.
  3. Dynamic finder through an association path next to createAlias in a withCriteria on the same class: same rows as the equivalent criteria.
  4. Data service @Where on 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).
  5. A where query with a subquery that correlates through an association ({alias} and an outer alias).
  6. not { } over a left-joined null: a missing association matches ne, does not match not { eq } (SQL three-valued logic, ne is x <> v or x is null as on H5).
  7. A named connection: the same association query on the second data source returns the rows of that data source.
  8. A multi-tenant domain: the tenant restriction and an association path together.
  9. isNull / isNotNull on an association through a left alias.
  10. 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 AliasPathModelSpec already 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

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

Activity

  1. borinquenkid commented on Nov 9, 2026

    @borinquenkid
    MemberAuthor

    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; ne through 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.

  2. added a commit that references this issue on Nov 10, 2026
  3. borinquenkid commented on Nov 12, 2026

    @borinquenkid
    MemberAuthor

    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)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions