Skip to content

fix(hibernate5): query arguments reach where queries and dynamic finders - #17078

Open
borinquenkid wants to merge 6 commits into
7.0.xfrom
fix/h5-criteria-query-args-7.0.x
Open

borinquenkid wants to merge 6 commits into
7.0.xfrom
fix/h5-criteria-query-args-7.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Hibernate 5 part of #16823 (item 2 of matrei's review), on 7.0.x so it merges up.

Part of #16808

The bug

findAll.adoc lists readOnly, fetchSize, timeout and flushMode for findAll(Map queryParams, Closure whereCriteria), and findAllBy.adoc lists them as metaParams of the dynamic finders. With Hibernate 5 they are ignored for both and for where queries: DynamicFinder and DetachedCriteria hand the arguments only to a query that implements QueryArgumentsAware, and the Hibernate 5 HibernateQuery did not. list(args) and createCriteria().list(args) already applied them.

The change

HibernateQuery implements QueryArgumentsAware, the hook both callers already use, so no extension point is added. setArguments sets fetchSize, timeout, readOnly and flushMode on the Hibernate criteria and leaves the other arguments (max, sort, ...) to the caller. A fetchSize or timeout that is not a whole number throws an IllegalArgumentException naming the argument. No public class or method is added beyond that interface method.

What changes for applications

Arguments that were ignored now apply. The upgrade note is in the new Grails 7.0.19 section and says how to keep the earlier result (remove the argument). This changes a result, so it needs two reviewers. The Hibernate 7 part is #17077 (8.0.x).

Tests

CriteriaQueryArgumentsSpec (10 features): readOnly through where.list, findAll(args) { } and a dynamic finder (true and false), a single result find, flushMode MANUAL against ALWAYS, and the whole number check. Without setArguments 6 of the 10 fail. The full grails-data-hibernate5-core suite passes.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

readOnly, fetchSize, timeout and flushMode are documented for findAll(Map, Closure), the dynamic finders and where queries, but the Hibernate 5 HibernateQuery did not implement QueryArgumentsAware, the hook both callers use, so they were dropped. No new extension point is added.

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

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@jamesfredley jamesfredley 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.

Requested changes. A page honors a manual flush. The count of that page still flushes.

… mode and the timeout of the query arguments

A where query listed with max and a flushMode of MANUAL did not flush for its page, but reading its
totalCount ran a copy of the query that had lost the setting, so the count flushed the pending change.
The query remembers the flush mode and the timeout it applied from the arguments and gives them to the copy.

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

Copy link
Copy Markdown
Member Author

@jamesfredley: the count behind the total of a page keeps the flush mode now. The query remembers the flushMode and timeout it applied from the arguments and gives them to the copy that runs the count, so where { ... }.list(max: 10, flushMode: 'MANUAL') neither flushes for its page nor for its totalCount. CriteriaQueryArgumentsSpec runs it in a session that flushes by itself, with MANUAL and ALWAYS; the MANUAL row fails without the change.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

…nt, and the query arguments are pinned on every entry point

A flushMode such as 'BOGUS' failed with the enum's own message, which does not name the argument, where a bad
fetchSize or timeout does. CriteriaQueryArgumentsSpec now runs readOnly and flushMode on every entry point (where list,
find, findAll with a closure, the finders, the paged forms), and a bad or null argument on each of them.

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

@jamesfredley jamesfredley 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.

Requested changes. A timeout of half a second is stored as no timeout.

@borinquenkid

Copy link
Copy Markdown
Member Author

@jamesfredley: before asking for another look, I ran each argument on each entry point, so the neighbours of the manual-flush case are in one place. CriteriaQueryArgumentsSpec now runs readOnly (true and false) and flushMode (MANUAL and ALWAYS, against a pending change) on seven entry points: where list, where find, findAll with a closure, findAllBy, findBy, a paged where and a paged finder, with the totals of the paged ones; it also runs a bad fetchSize, timeout and flushMode, and null arguments, on the entry points that take them. All the rows gave the expected result except one: a flushMode that is not a Hibernate FlushMode failed with the enum's own message, No enum constant ...FlushMode.BOGUS, which does not name the argument as a bad fetchSize or timeout does. It now says The flushMode argument must be one of [...] but was [BOGUS], and the upgrade note says so. Five rows fail without that change.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@jamesfredley jamesfredley 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.

Requested changes. A timeout of half a second is still stored as no timeout.

@borinquenkid

Copy link
Copy Markdown
Member Author

@jamesfredley: list(timeout: 0.5) is refused now, and so is any fetchSize or timeout with a fraction. The conversion cut a number to its whole part (0.5 became 0, which is no timeout) and wrapped a number past the largest int; it now accepts only a number that is whole and fits in an int, as a number or as text, and names the argument in the message. A whole double such as 3.0 and the text 9.0 are still accepted.

Before asking for another look, I tried 18 values (whole numbers as int, long, double, decimal and text, padded text, fractions as double, float, decimal and text, empty and non-numeric text, a long and a decimal past the largest int, NaN and infinity) for both arguments on four entry points: the where list, findAll with a closure, findAllBy and a paged where list. 144 rows; 64 of them fail without this change.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@testlens-app

testlens-app Bot commented Nov 20, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 13ddecf
▶️ Tests: 58051 executed
⚪️ Checks: 57/57 completed


Learn more about TestLens at testlens.app/docs.

@borinquenkid

Copy link
Copy Markdown
Member Author

@matrei: the notes are back under === Grails 7.0.18 in upgrading60x.adoc, as your correction asks; the 7.0.19 heading is gone. If 7.0.18 is staged again before this merges, I move them. Only the upgrade notes changed.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@borinquenkid

Copy link
Copy Markdown
Member Author

@jamesfredley: I ran every query setting (flush mode, lock, cache, read-only) through every paged route, to find the cases around the one you found on where queries. One more was left: createCriteria().list(max: 10, flushMode: 'MANUAL') { ... } left the pending change out of the page, and reading totalCount still flushed it. The count of a paged criteria keeps the flush mode and the timeout of the arguments now, and CriteriaQueryArgumentsSpec has a MANUAL and an ALWAYS row for it (the MANUAL row fails without the change). No count ran for update and none was put in the query cache on any route, as documented. The whole grails-data-hibernate5-core module passes.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@jamesfredley jamesfredley 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.

The items this review found have been addressed. A timeout that is not a whole number is refused, and the count keeps the flush mode.

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