You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/04/09 14:53:21 UTC
(grails-core) 40/40: fix(test): correct GormCriteriaQueriesSpec to use safe HQL overloads and proper applicationClass
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch 8.0.x-hibernate7-dev
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 0aa78724bed48e5327feacd567b04235f09b7557
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Thu Apr 9 09:44:34 2026 -0500
fix(test): correct GormCriteriaQueriesSpec to use safe HQL overloads and proper applicationClass
- Replace executeQuery(plainString) and executeUpdate(plainString) calls
with the (String, Map) overloads (empty map for parameterless queries).
HibernateGormStaticApi intentionally rejects plain String in the
no-arg overload to prevent HQL injection; parameterless static queries
must use the Map overload.
- Add applicationClass = Application to @Integration so the spec shares
the same application context and transaction manager as the other specs
in this module, preventing test-data bleed between specs.
Co-authored-by: Copilot <22...@users.noreply.github.com>
---
.../groovy/gorm/GormCriteriaQueriesSpec.groovy | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/grails-test-examples/gorm/src/integration-test/groovy/gorm/GormCriteriaQueriesSpec.groovy b/grails-test-examples/gorm/src/integration-test/groovy/gorm/GormCriteriaQueriesSpec.groovy
index 920f9e9ed2..364fa7e907 100644
--- a/grails-test-examples/gorm/src/integration-test/groovy/gorm/GormCriteriaQueriesSpec.groovy
+++ b/grails-test-examples/gorm/src/integration-test/groovy/gorm/GormCriteriaQueriesSpec.groovy
@@ -24,7 +24,6 @@ import spock.lang.Unroll
import grails.gorm.DetachedCriteria
import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
-
/**
* Tests for GORM Criteria Queries - both createCriteria() and DetachedCriteria.
*
@@ -32,7 +31,7 @@ import grails.testing.mixin.integration.Integration
* complex queries without writing HQL strings.
*/
@Rollback
-@Integration
+@Integration(applicationClass = Application)
class GormCriteriaQueriesSpec extends Specification {
def setup() {
@@ -489,8 +488,8 @@ class GormCriteriaQueriesSpec extends Specification {
// ============================================
void "test basic HQL query"() {
- when: "executing HQL query"
- def results = Book.executeQuery("from Book where inStock = true")
+ when: "executing HQL query with no parameters (use Map overload for plain strings)"
+ def results = Book.executeQuery("from Book where inStock = true", [:])
then: "results returned"
results.size() == 6
@@ -545,7 +544,7 @@ class GormCriteriaQueriesSpec extends Specification {
void "test HQL aggregate functions"() {
when: "executing HQL aggregates"
def result = Book.executeQuery(
- 'select count(b), avg(b.price), max(b.pageCount) from Book b'
+ 'select count(b), avg(b.price), max(b.pageCount) from Book b', [:]
)[0]
then: "aggregates calculated"
@@ -557,7 +556,7 @@ class GormCriteriaQueriesSpec extends Specification {
void "test HQL group by"() {
when: "executing HQL group by"
def results = Book.executeQuery(
- 'select a.name, count(b) from Book b join b.author a group by a.name order by count(b) desc'
+ 'select a.name, count(b) from Book b join b.author a group by a.name order by count(b) desc', [:]
)
then: "grouped results"
@@ -569,7 +568,7 @@ class GormCriteriaQueriesSpec extends Specification {
void "test executeUpdate for bulk operations"() {
when: "executing bulk update"
int updated = Book.executeUpdate(
- 'update Book b set b.price = b.price * 1.1 where b.inStock = true'
+ 'update Book b set b.price = b.price * 1.1 where b.inStock = true', [:]
)
then: "bulk update applied"