Skip to content

test(hibernate7): run the where query functions on a SQL Server container - #16962

Open
borinquenkid wants to merge 5 commits into
fix/h7-where-query-functions-8.0.xfrom
test/h7-where-functions-sqlserver-8.0.x
Open

borinquenkid wants to merge 5 commits into
fix/h7-where-query-functions-8.0.xfrom
test/h7-where-functions-sqlserver-8.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Runs the where query functions of WhereQueryFunctionsDialectSpec on a real SQL Server, the database the dialect specs did not cover. Closes #16932.

The reviewer of #16816 wrote that an empty list in a function comparison "still throws on a database that rejects an empty IN list". The empty list was run on PostgreSQL, MySQL, MariaDB and Oracle; SQL Server was the database left. On a real SQL Server, every row passes as it does on the others:

  • the date functions (year, month, day, hour, minute, second) on a read and in a bulk delete,
  • a function compared with a fraction (length(name) > 2.5, upper(name) = 3.5) on a read and in a bulk delete,
  • an empty list (upper(name) in []) and a subquery without projection, on a read and in a bulk update and delete.

No defect found, so no production code changes. Test code only.

Stacked twice, on purpose: the spec exists only in #16816, so this PR's base is #16816's branch (fix/h7-where-query-functions-8.0.x); the SQL Server container comes from #16954, whose branch is merged into this one, so its commits show here until #16954 lands. After #16816 and #16954 merge, this retargets 8.0.x and shows only its own commit.

Verified locally on a real SQL Server container (14 rows pass, the Db2 row skips on this arm machine); CodeNarc, Checkstyle and rat are clean. CI is off (no ci). Two reviewers (matrei and codeconsole), as 8.0.x is released.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

…n a SQL Server container

Transact-SQL has no boolean value for a predicate, so the like that rlike falls back to
rendered as 'name LIKE ?=?' and failed with 'Incorrect syntax near =' on a real SQL Server.
It is now the condition of a CASE that gives a bit, which the query compares with true.

DatabaseContainers gains SQL Server, and the two rlike features run on it. Sybase, Db2 for
IBM i and Db2 for z/OS cannot run in a container, so their rows are not changed and each
constant says that no test runs it.

Refs #16881

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

SQL Server was the database left that no dialect spec covered. The date functions, the fraction comparison and the
empty list (a read, and a bulk update and delete) all match what the other databases return on a real SQL Server.

Refs #16932

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:53

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.

Not approving. Adding the web datastore module turns on an interceptor that closes the outer session during an include, and that leaves a session bound to the first thread of an asynchronous request.

runtimeOnly project(':grails-data-mongodb-ext'), {
// Include MongoDB groovy extensions for applications
}
runtimeOnly project(':grails-datastore-web'), {

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.

This dependency registers the open-session interceptor. An include reuses the outer session, and the interceptor then unbinds and disconnects it before the outer transaction finishes. An asynchronous request binds a session to the first thread and never releases it when the work moves to another thread, so a later request can see that session. Track participation, and release the session when asynchronous handling starts, before this dependency is on by default.

@borinquenkid

Copy link
Copy Markdown
Member Author

The line you commented on, runtimeOnly project(':grails-datastore-web') in grails-data-mongodb/grails-plugin/build.gradle, is not part of this pull request. It comes from "Keep a session open for each request in a MongoDB application" (610d8a8), which is already in 8.0.x through the merge of 7.2.x. It shows up in the diff of this pull request only because the base of this stack (fix/h7-where-query-functions-8.0.x) has not been updated to the current 8.0.x yet.

What this pull request adds is the commit 1711fef: the where query functions run on a SQL Server container, plus the stacked branch of the SQL Server rlike change it builds on. It does not touch the MongoDB plugin or the open-session interceptor.

The two problems you describe are real questions about that change: an include that reuses the outer session while the interceptor unbinds and disconnects it, and an asynchronous request that binds a session to its first thread. I have not run either. They belong on the pull request or issue of the MongoDB change, not on this stack, so I will not change anything here for them. If you would like, I can open an issue with the two cases you wrote so they are tracked.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

matrei
matrei previously approved these changes Nov 19, 2026

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

Reviewed at 1711fef (base fix/h7-where-query-functions-8.0.x, #16816's head branch). This PR's own change is that commit: seven lines in WhereQueryFunctionsDialectSpec. The rest of the 126 files GitHub shows come from the branch of #16954, merged at e5397ed, one commit before its head, and from the history of #16816 before its latest merges of 8.0.x: this branch has not merged #16816's head (2c6b447). The PR is labelled no ci.

What I ran locally:

  • WhereQueryFunctionsDialectSpec at this head, on an x86_64 machine with Docker: all 14 rows pass, the four SQL Server rows included, and so does the Db2 row, which the arm64 machine of the description skips. Db2 took about 150 seconds to start, SQL Server about 55.

For Hibernate 7, the branch is right: the spec exists only in #16816 and the SQL Server container only in #16954, so retargeting 8.0.x once both are merged, as the description plans, is the way it can go in. The change only adds rows to a test, so it needs one approval. The two reviewers of the rule in the dev@ thread are for a change that alters a result.

On James's review: the line he commented on, runtimeOnly project(':grails-datastore-web') in grails-data-mongodb/grails-plugin/build.gradle, is not part of this change, as you wrote. It came with #16899 on 7.0.x and reached 8.0.x through the merge-ups. His two cases, an include that reuses the outer session and an asynchronous request, are about that change, so the issue you offered, linked to #16899, is the place for them.

Suggestions

  1. startOn now starts a container that is not running, so the Oracle and Db2 feature's own if (!container.isRunning()) { container.start() } can go.
  2. The spec creates Postgres, MySQL and MariaDB containers of its own. RLikeHibernate7Spec, NativeIdGeneratorHibernate7Spec and SharedJoinTableHibernate7Spec use DatabaseContainers.POSTGRES, MYSQL and MARIADB, which a test JVM starts once for all of them. Using those here too would save starting a second container of each.

sbglasius
sbglasius previously approved these changes Nov 22, 2026

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

This an AI assisted review

Reviewed at 1711fef. This PR's own change is that one commit: seven lines in WhereQueryFunctionsDialectSpec, which add a SQL Server row to the three features that run on every database, and make startOn start a container that is not running. The other files in the diff come from #16954 (merged in at e5397ed) and from the history of #16816. The test only uses public GORM APIs (DetachedCriteria.list, updateAll, deleteAll), and there is no production change.

I ran ./gradlew :grails-data-hibernate7-core:test --tests "grails.gorm.tests.detachedcriteria.WhereQueryFunctionsDialectSpec" on x86_64 with Docker. All 14 rows passed and none were skipped: the four SQL Server rows, and the Oracle and Db2 rows too.

This closes the gap #16932 describes: an empty list in a function comparison (upper(name) in []) on a read and in a bulk update and delete, now on SQL Server too.

Two small notes, neither blocking:

  • The base has moved since this branch last merged it. fix/h7-where-query-functions-8.0.x is now at 85c8df3, and this branch does not contain it. That will sort itself out when this PR is retargeted to 8.0.x, but the SQL Server rows are worth running once more after the retarget.
  • +1 to matrei's first suggestion. startOn now starts the container itself, so the if (!container.isRunning()) block in the Oracle and Db2 feature is no longer needed.

@Shared MariaDBContainer mariadb = new MariaDBContainer('mariadb:10.11')
@Shared oracle = DatabaseContainers.ORACLE
@Shared db2 = DatabaseContainers.DB2
@Shared sqlServer = DatabaseContainers.SQL_SERVER

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 class Javadoc above (line 37) still lists the databases without SQL Server. Maybe add something like: "SQL Server runs every feature; its image is amd64 only, so on arm64 it runs under emulation and is slow to start." That way a reader knows why a SQL Server row can take minutes on an arm machine.

'Postgres' | postgres
'MySQL' | mysql
'MariaDB' | mariadb
'SQL Server' | sqlServer

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.

Nit: 'SQL Server' is wider than the db column, so the | no longer lines up with the rows above it. The same happens at lines 144 and 170. Padding db, 'Postgres', 'MySQL' and 'MariaDB' to the width of 'SQL Server' keeps the three tables aligned.

@borinquenkid

Copy link
Copy Markdown
Member Author

Merged fix/h7-where-query-functions-8.0.x (c4d2c24, which has 8.0.x merged in) into this branch, which resolves the conflict with its base. No file of this PR changed. The H7 core module passes with the SQL Server rows run in the container; the Db2 rows are skipped on arm64.

@github-actions
github-actions Bot dismissed stale reviews from matrei and sbglasius November 23, 2026 17:05

Dismissed automatically: the pull request changed after this approval, from 1711fef to 992696b.

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.

5 participants