Skip to content

fix(hibernate7): support scalar subqueries in comparison criteria - #16817

Open
borinquenkid wants to merge 6 commits into
fix/h7-where-query-functions-8.0.xfrom
fix/h7-scalar-subqueries-comparisons-8.0.x
Open

borinquenkid wants to merge 6 commits into
fix/h7-where-query-functions-8.0.xfrom
fix/h7-scalar-subqueries-comparisons-8.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Summary

Supports scalar QueryableCriteria subqueries in comparison criteria (GreaterThan, GreaterThanEquals, LessThan, LessThanEquals) within PropertyCriterionHandler.

  • Builds a JPA Subquery expression when the criterion value is a QueryableCriteria instead of converting the value as a scalar literal/parameter.
  • Infers the subquery return type via resolveSubqueryType from scalar projections (AvgProjection, CountProjection, CountDistinctProjection, IdProjection, PropertyProjection).

Note: Chained on #16816 (fix/h7-where-query-functions-8.0.x).

Fixes #16812

Copilot AI balanced review requested due to automatic review settings November 1, 2026 01:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The scalar-comparison tests lack result-based coverage for several projection types and an equality case needed to distinguish inclusive from strict comparison operators.

2 open issues
What changed in this PR

Adds scalar subquery support to Hibernate 7 comparison criteria, addressing #16812 and building on the query-handler refactoring in #16816.

Changes:

  • Builds subquery expressions for gt, ge, lt, and le instead of treating criteria objects as scalar values.
  • Infers subquery result types from aggregate, identifier, and property projections.
  • Adds direct criteria and where-query regression tests.
File Description
grails-data-hibernate7/​core/​src/​test/​groovy/​grails/​orm/​HibernateCriteriaBuilderDirectSpec.groovy Adds result-based scalar comparison and aggregate where-query tests.
grails-data-hibernate7/​core/​src/​test/​groovy/​grails/​gorm/​tests/​hibernatequery/​PredicateGeneratorSpec.groovy Checks predicate construction for all four scalar-subquery comparisons.
grails-data-hibernate7/​core/​src/​main/​groovy/​org/​grails/​orm/​hibernate/​query/​PropertyCriterionHandler.java Handles comparison subqueries and resolves projection-based result types.

Review effort: Balanced

Handle QueryableCriteria values in GreaterThan, GreaterThanEquals,
LessThan, and LessThanEquals criteria within PropertyCriterionHandler
by building a JPA Subquery expression instead of converting the criteria
as a literal value. Infer the subquery return type from its projections
for aggregate, identifier, and property projections.

Fixes #16812
… on H5 and H7

Add integration scenarios to the Hibernate 5 and Hibernate 7 grails-hibernate test apps
that compare a property with avg, max and min subqueries (>, >=, <, <=, ==, !=), use a
subquery in an in list, and combine one with another criterion, through where queries
and the criteria builder. Both modules return the same rows, and the scenarios fail
when the greater-than, less-than, equal or not-equal subquery branch is changed.
@borinquenkid borinquenkid added this to the grails:8.0.1 milestone Nov 4, 2026
…s-comparisons-8.0.x

Takes the review changes of #16816: the merge of 8.0.x with #16573, the subquery criteria joined with AND, the function list, the
rejection of a function over an rlike in a bulk statement, the package-private criterion handlers and the restored SPI documentation.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

This branch has not been deployed

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

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants