Repository navigation
fix(hibernate7): support scalar subqueries in comparison criteria - #16817
Open
borinquenkid wants to merge 6 commits into
Open
borinquenkid wants to merge 6 commits into
borinquenkid wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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, andleinstead 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
borinquenkid
force-pushed
the
fix/h7-where-query-functions-8.0.x
branch
from
November 1, 2026 05:03
89cd64d to
d0ff76b
Compare
borinquenkid
force-pushed
the
fix/h7-scalar-subqueries-comparisons-8.0.x
branch
from
November 1, 2026 16:34
274dd40 to
25448d5
Compare
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
borinquenkid
force-pushed
the
fix/h7-scalar-subqueries-comparisons-8.0.x
branch
from
November 1, 2026 16:47
25448d5 to
323473b
Compare
This was referenced Nov 1, 2026
…s-comparisons-8.0.x
… 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.
…abase error on H5 and H7
… on H5 and H7 Claude-Session: https://claude.ai/code/session_01Dmki4SQGwRSj8pRJ5KCWyX
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Supports scalar
QueryableCriteriasubqueries in comparison criteria (GreaterThan,GreaterThanEquals,LessThan,LessThanEquals) withinPropertyCriterionHandler.Subqueryexpression when the criterion value is aQueryableCriteriainstead of converting the value as a scalar literal/parameter.resolveSubqueryTypefrom scalar projections (AvgProjection,CountProjection,CountDistinctProjection,IdProjection,PropertyProjection).Fixes #16812