Skip to content

Hibernate 7: leave the criteria's orders out of a count query - #16731

Merged
borinquenkid merged 1 commit into
8.0.xfrom
fix/criteria-count-ignores-orders-8.0.x
Oct 23, 2026
Merged

borinquenkid merged 1 commit into
8.0.xfrom
fix/criteria-count-ignores-orders-8.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Summary

count() on a DetachedCriteria or a criteria builder that also has an order threw on H2:

Column "CTE1_0.AMOUNT" must be in the GROUP BY list
select count(cte1_0.id) from criteria_test_entity cte1_0 order by cte1_0.amount

A count has one row whatever the order, and an ORDER BY on a column that is not aggregated fails on H2 and most other databases. Only the paged-list total escaped it, because HibernatePagedResultList clears the orders before it counts.

JpaCriteriaQueryCreator now leaves the criteria's orders out when every projection of the query is a count, which is how count() and countDistinct() set the query up. A query that groups and counts keeps its orders, so projections { groupProperty(...); count(...) } with an order is unchanged.

Found while reviewing #16696 (jdaugherty's comment on assignOrderBy): that PR adds order handlers, whose orders run into the same count path, and its docs currently tell every handler to return null for a count. With this fix the framework drops the orders instead, so that advice can go.

Verification

  • New feature in HibernateCriteriaBuilderDirectSpec: DetachedCriteria.count() with an order, with a criterion and an order, rowCount() with an order through the builder, createCriteria().count { order(...) }, and the order still applying to list(). It failed with the error above before the fix.
  • :grails-data-hibernate7-core:test: 3,794 tests, 0 failures, 59 skipped.
  • checkstyleMain and codenarcTest for the module: clean.

A count has one row whatever the order, and an ORDER BY on a column that is
not aggregated fails on H2 and most other databases, so `count()` on a
DetachedCriteria or a criteria builder with an `order` threw a
SQLGrammarException ("Column ... must be in the GROUP BY list"). Only the
paged-list total escaped it, because it clears the orders first.

JpaCriteriaQueryCreator now skips the orders when every projection of the
query is a count, as `count()` and `countDistinct()` set it up. A query that
groups and counts keeps its orders.

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 reached their quota limit.

@testlens-app

testlens-app Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

Tip

Inspect all details with the TestLens CLI: testlens pr 16731

CI / Build Grails-Core (Windows JDK 25 shard 2) > :grails-shell-cli:test

Test Runs Flakiness
SpringApplicationRunnerSpec > ROOT OFF prints #failureMode failures to stderr > ROOT OFF prints reload failures to stderr ❌ ✅ 1% 🟡

Groovy Snapshot Canary Build / Build Grails (shard 0) > :grails-test-examples-mongodb-hibernate5:test

Test Runs Flakiness
BookFongoSpec ❌ 🚫 1% 🟡

Groovy Snapshot Canary Build / Build Grails (shard 1) > :grails-data-mongodb-core:test (first 40 of 225)

Test Runs Flakiness
AggregateMethodSpec ❌ 🚫 1% 🟡
AssignedIdentifierSpec ❌ 🚫 1% 🟡
AttachMethodSpec ❌ 🚫 1% 🟡
AutowireServicesSpec ❌ 🚫 1% 🟡
BasicArraySpec ❌ 🚫 1% 🟡
BasicCollectionTypeSpec ❌ 🚫 1% 🟡
BasicCollectionsSpec ❌ 🚫 1% 🟡
BatchUpdateDeleteSpec ❌ 🚫 1% 🟡
BeforeInsertUpdateSpec ❌ 🚫 1% 🟡
BeforeUpdatePropertyPersistenceSpec ❌ 🚫 1% 🟡
BigDecimalSpec ❌ 🚫 1% 🟡
BrokenManyToManyAssociationSpec ❌ 🚫 1% 🟡
BuildIndexAsyncResultSpec ❌ 🚫 1% 🟡
BuildIndexesAsyncSpec ❌ 🚫 1% 🟡
BuildIndexesBackgroundFailureSpec ❌ 🚫 1% 🟡
BuildIndexesClassificationCostSpec ❌ 🚫 1% 🟡
BuildIndexesDefaultConstraintsSpec ❌ 🚫 1% 🟡
BuildIndexesDisabledSpec ❌ 🚫 1% 🟡
BuildIndexesEnabledByDefaultSpec ❌ 🚫 1% 🟡
BuildIndexesFailureSummarySpec ❌ 🚫 1% 🟡
BuildIndexesHookSpec ❌ 🚫 1% 🟡
BuildIndexesKeyOrderSpec ❌ 🚫 1% 🟡
BuildIndexesLifecycleSpec ❌ 🚫 1% 🟡
BuildIndexesNameConflictSpec ❌ 🚫 1% 🟡
BuildIndexesOnDemandSpec ❌ 🚫 1% 🟡
BuildIndexesPartialClassificationSpec ❌ 🚫 1% 🟡
BuildIndexesPerConnectionSpec ❌ 🚫 1% 🟡
BuildIndexesRecreateSummarySpec ❌ 🚫 1% 🟡
BuildIndexesSharedDeclarationSpec ❌ 🚫 1% 🟡
BuildIndexesStaleSnapshotSpec ❌ 🚫 1% 🟡
BuildIndexesSummaryLogSpec ❌ 🚫 1% 🟡
BuildIndexesUnfinishedSummarySpec ❌ 🚫 1% 🟡
BuildIndexesUnreadableIndexListSpec ❌ 🚫 1% 🟡
BuiltinUniqueConstraintWorksWithTargetProxiesConstraintsSpec ❌ 🚫 1% 🟡
CascadeDeleteOneToOneSpec ❌ 🚫 1% 🟡
CascadeDeleteSpec ❌ 🚫 1% 🟡
CheckpointRestoreConnectionsSpec ❌ 🚫 1% 🟡
CircularBidirectionalOneToManySpec ❌ 🚫 1% 🟡
CircularEmbeddedListSpec ❌ 🚫 1% 🟡
CircularOneToManySpec ❌ 🚫 1% 🟡

Groovy Snapshot Canary Build / Build Grails (shard 1) > :grails-test-examples-mongodb-test-data-service:integrationTest

Test Runs Flakiness
StudentServiceSpec > test regular service autowire by type in a Data Service ❌ 🚫 1% 🟡
TestServiceSpec > test autowire by name works ❌ 🚫 1% 🟡
TestServiceSpec > test autowire by type ❌ 🚫 1% 🟡
TestServiceSpec > test data-service is loaded correctly ❌ 🚫 1% 🟡
TestServiceSpec > test that there is only one bookService ❌ 🚫 1% 🟡

Groovy Snapshot Canary Build / Build Grails (shard 2) > :grails-data-mongodb-spring-boot:test

Test Runs Flakiness
MongoDbGormAutoConfigurationDiscoverySpec ❌ 🚫 0% 🟢
MongoDbGormAutoConfigurationSpec ❌ 🚫 0% 🟢
MongoDbGormAutoConfigureWithGeoSpacialSpec ❌ 🚫 0% 🟢

Groovy Snapshot Canary Build / Build Grails (shard 2) > :grails-test-examples-mongodb-base:test

Test Runs Flakiness
BookUnitSpec ❌ 🚫 0% 🟢
LocalMongoUnitSpec ❌ 🚫 0% 🟢
PersonSpec ❌ 🚫 0% 🟢
TeamUnitSpec ❌ 🚫 0% 🟢

🏷️ Commit: ebc4b2a
▶️ Tests: 4581 executed
⚪️ Checks: 92/92 completed

Test Failures (first 10 of 236)

BookFongoSpec (:grails-test-examples-mongodb-hibernate5:test in Groovy Snapshot Canary Build / Build Grails (shard 0) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at functional.tests.EmbeddedMongoClient$Trait$Helper.createMongoClient(EmbeddedMongoClient.groovy:33)
	at grails.test.mongodb.MongoSpec.setupSpec(MongoSpec.groovy:117)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
AggregateMethodSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
AssignedIdentifierSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
AttachMethodSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
AutowireServicesSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
BasicArraySpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
BasicCollectionTypeSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
BasicCollectionsSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
BatchUpdateDeleteSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more
BeforeInsertUpdateSpec (:grails-data-mongodb-core:test in Groovy Snapshot Canary Build / Build Grails (shard 1) | Attempt 1/2)
org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mongo:8.0
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:346)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
	at org.apache.grails.data.mongo.core.GrailsDataMongoTckManager.setupSpec(GrailsDataMongoTckManager.groovy:80)
	at org.apache.grails.data.testing.tck.base.GrailsDataTckSpec.setupSpec(GrailsDataTckSpec.groovy:40)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:331)
	... 3 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:551)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:341)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 4 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:520)
	... 6 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '(?i).*waiting for connections.*'
	at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
	at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
	at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:904)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:487)
	... 6 more

Learn more about TestLens at testlens.app/docs.

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.2245%. Comparing base (a348ef9) to head (ebc4b2a).
⚠️ Report is 15 commits behind head on 8.0.x.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16731        +/-   ##
==================================================
+ Coverage     62.1821%   62.2245%   +0.0423%     
- Complexity      26900      26926        +26     
==================================================
  Files            2241       2241                
  Lines          110736     110741         +5     
  Branches        20218      20218                
==================================================
+ Hits            68858      68908        +50     
+ Misses          32615      32568        -47     
- Partials         9263       9265         +2     

see 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Approving. A count-only projection no longer gets the criteria's ORDER BY. The stored orders are unchanged, so the list query still sorts. DISTINCT and GROUP BY stay on the count path that needs them.

@borinquenkid
borinquenkid merged commit 52dc53d into 8.0.x Oct 23, 2026
162 of 169 checks passed

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

@borinquenkid two follow-ups from running this against 8.0.x after the merge. Neither is blocking, and the fix itself checks out: asBoolean(), countDistinct and an order on an association path are covered as well, and the grouped count and the derived-table countResults() path are unchanged.

  1. Hibernate 5 has the same bug. On 8.0.x, grails-data-hibernate5 emits

    select count(*) as y0_ from count_order_probe_entity this_ order by this_.amount desc
    

    for DetachedCriteria.count(), createCriteria().count {} and asBoolean() with an order, and H2 2.x rejects it with the same 90016. There the orders go onto the Hibernate Criteria as order() is called (AbstractHibernateQuery.order), so the H5 fix would drop them in countResults() and the builder's count branch rather than at build time. Would you take that as a sibling PR?

  2. #16696 can now drop the "return null on a count" advice from the docs and the OrderHandler javadoc and add a count() case with an order handler, as noted on that PR.

private boolean isCountOnly() {
List<Query.Projection> projectionList = projections.getProjectionList();
return !projectionList.isEmpty() && projectionList.stream()
.allMatch(projection -> projection instanceof Query.CountProjection ||

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 predicate covers count and countDistinct, so a query whose only projections are other aggregates still carries the orders and fails the same way:

c.get { projections { max('amount') }; order('amount') }

Column "CTE1_0.AMOUNT" must be in the GROUP BY list
select max(cte1_0.amount) from criteria_test_entity cte1_0 order by cte1_0.amount

That one is user-written rather than added by the framework, so it is less pressing than count(), but the rule could be "no group by and every projection is an aggregate" (count, countDistinct, max, min, sum, avg) at no extra cost. A follow-up PR is fine.

borinquenkid added a commit that referenced this pull request Oct 23, 2026
10.0.x changed three of the Java files this branch converts: #16574 gave BidirectionalOneToManyLinker a
CompositeIdentifierToManyToOneBinder, aligned the to-one side first and marks the copied key sorted, and #16731 leaves the
criteria's orders out of a count-only query in JpaCriteriaQueryCreator. CollectionBinder merged on its own; the other two are
ported into their Groovy files by hand, in the style of the conversion, and JpaCriteriaQueryCreator.java stays deleted.

Claude-Session: https://claude.ai/code/session_01MDHn7fC3hsGJ27vFHD2o1p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants