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/06/24 22:00:36 UTC

(grails-core) branch 8.0.x-hibernate7 updated (6505db22bb -> 543c691e42)

This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a change to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git


    from 6505db22bb Address remaining PR review feedback from matrei
     new 2d12e77021 Replace find*WithSql/find*WithNativeSql with withSql/withAllSql in HibernateEntity
     new ccafa5e0bd Correct withSql/withAllSql implementation: H7 only, H5 unchanged
     new 64e141ad5f Remove withSql/withAllSql from HibernateEntity H7 — no new public API
     new 96e732d705 Align H7 HibernateEntity public API with H5: findWithSql/findAllWithSql
     new 543c691e42 Remove deprecated findWithSql/findAllWithSql from HibernateGormStaticApi

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../grails/gorm/hibernate/HibernateEntity.groovy   | 69 ++++++----------------
 .../orm/hibernate/HibernateGormStaticApi.groovy    | 12 ----
 .../hibernate/HibernateGormStaticApiSpec.groovy    | 26 +-------
 3 files changed, 20 insertions(+), 87 deletions(-)


(grails-core) 02/05: Correct withSql/withAllSql implementation: H7 only, H5 unchanged

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit ccafa5e0bd2405ad10bf4b20bf184591ba61f091
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Jun 24 16:35:16 2026 -0500

    Correct withSql/withAllSql implementation: H7 only, H5 unchanged
    
    H7 HibernateEntity now adds withSql/withAllSql alongside the existing
    findWithNativeSql/findAllWithNativeSql and deprecated findWithSql/findAllWithSql
    methods — no removal of existing methods. The new methods use the same private
    helper pattern as H5 (currentHibernateStaticApi()) instead of inline casting.
    
    H5 HibernateEntity is reverted to its original state — no new methods, no
    deprecation annotations added.
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 .../grails/orm/hibernate/HibernateEntity.groovy    |  76 ++++-----------
 .../tests/HibernateEntityTraitGeneratedSpec.groovy |   4 -
 .../groovy/grails/gorm/tests/SqlQuerySpec.groovy   |   6 +-
 .../grails/gorm/hibernate/HibernateEntity.groovy   | 103 +++++++++++++++++++--
 .../orm/hibernate/HibernateGormStaticApi.groovy    |  12 +++
 .../tests/HibernateEntityTraitGeneratedSpec.groovy |  12 ++-
 .../hibernate/HibernateGormStaticApiSpec.groovy    |  22 +++++
 7 files changed, 160 insertions(+), 75 deletions(-)

diff --git a/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy b/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy
index 1a2380b23e..555a69c061 100644
--- a/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy
+++ b/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy
@@ -36,82 +36,46 @@ import org.grails.orm.hibernate.AbstractHibernateGormStaticApi
 trait HibernateEntity<D> extends GormEntity<D> {
 
     /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
+     * Finds all objects for the given string-based query
      *
-     * @param sql The native SQL query
-     * @return The entity, or {@code null} if none matched
-     * @since 8.0
-     */
-    @Generated
-    static D withSql(CharSequence sql) {
-        currentHibernateStaticApi().findWithSql(sql, Collections.emptyMap())
-    }
-
-    /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
+     * @param sql The query
      *
-     * @param sql  The native SQL query
-     * @param args Pagination/query settings (max, offset, cache, etc.)
-     * @return The entity, or {@code null} if none matched
-     * @since 8.0
+     * @return The object
      */
     @Generated
-    static D withSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findWithSql(sql, args)
-    }
-
-    /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
-     *
-     * @param sql The native SQL query
-     * @return The matching objects
-     * @since 8.0
-     */
-    @Generated
-    static List<D> withAllSql(CharSequence sql) {
+    static List<D> findAllWithSql(CharSequence sql) {
         currentHibernateStaticApi().findAllWithSql(sql, Collections.emptyMap())
     }
 
     /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
+     * Finds an entity for the given SQL query
      *
-     * @param sql  The native SQL query
-     * @param args Pagination/query settings (max, offset, cache, etc.)
-     * @return The matching objects
-     * @since 8.0
+     * @param sql The sql query
+     * @return The entity
      */
     @Generated
-    static List<D> withAllSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findAllWithSql(sql, args)
-    }
-
-    /** @deprecated Use {@link #withAllSql(CharSequence)} */
-    @Deprecated
-    @Generated
-    static List<D> findAllWithSql(CharSequence sql) {
-        currentHibernateStaticApi().findAllWithSql(sql, Collections.emptyMap())
-    }
-
-    /** @deprecated Use {@link #withSql(CharSequence)} */
-    @Deprecated
-    @Generated
     static D findWithSql(CharSequence sql) {
         currentHibernateStaticApi().findWithSql(sql, Collections.emptyMap())
     }
 
-    /** @deprecated Use {@link #withAllSql(CharSequence, Map)} */
-    @Deprecated
+    /**
+     * Finds all objects for the given string-based query
+     *
+     * @param sql The query
+     *
+     * @return The object
+     */
     @Generated
     static List<D> findAllWithSql(CharSequence sql, Map args) {
         currentHibernateStaticApi().findAllWithSql(sql, args)
     }
 
-    /** @deprecated Use {@link #withSql(CharSequence, Map)} */
-    @Deprecated
+    /**
+     * Finds an entity for the given SQL query
+     *
+     * @param sql The sql query
+     * @return The entity
+     */
     @Generated
     static D findWithSql(CharSequence sql, Map args) {
         currentHibernateStaticApi().findWithSql(sql, args)
diff --git a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
index e4fd4c4f2c..93d37b4e78 100644
--- a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
+++ b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
@@ -34,10 +34,6 @@ class HibernateEntityTraitGeneratedSpec extends Specification {
     void "test that all HibernateEntity trait methods are marked as Generated"() {
         // Unfortunately static methods have to check directly one by one
         expect:
-        Club.getMethod('withAllSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('withSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('withAllSql', CharSequence, Map).isAnnotationPresent(Generated)
-        Club.getMethod('withSql', CharSequence, Map).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findWithSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithSql', CharSequence, Map).isAnnotationPresent(Generated)
diff --git a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
index c30bb93c4b..d7a69c7b28 100644
--- a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
+++ b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
@@ -41,7 +41,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String name = "Arsenal"
-        Club c = Club.withSql("select * from club c where c.name = $name")
+        Club c = Club.findWithSql("select * from club c where c.name = $name")
 
         then:"The results are correct"
         c != null
@@ -55,7 +55,7 @@ class SqlQuerySpec extends Specification {
         setupTestData()
 
         when:"Some test data is saved"
-        List<Club> results = Club.withAllSql("select * from club c order by c.name")
+        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -69,7 +69,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.withAllSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.findAllWithSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2
diff --git a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
index 5a804135e4..fee53485e7 100644
--- a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
@@ -43,15 +43,15 @@ trait HibernateEntity<D> extends GormEntity<D> {
     /**
      * Finds an entity for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
+     * Use this method (not {@code find}) when you need raw SQL rather than HQL.
      *
      * @param sql The native SQL query
-     * @return The entity, or {@code null} if none matched
+     * @return The entity
      * @since 8.0
      */
     @Generated
     static D withSql(CharSequence sql) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (D) api.findWithNativeSql(sql, Collections.emptyMap())
+        currentHibernateStaticApi().findWithNativeSql(sql, Collections.emptyMap())
     }
 
     /**
@@ -60,18 +60,18 @@ trait HibernateEntity<D> extends GormEntity<D> {
      *
      * @param sql  The native SQL query
      * @param args Pagination/query settings (max, offset, cache, etc.)
-     * @return The entity, or {@code null} if none matched
+     * @return The entity
      * @since 8.0
      */
     @Generated
     static D withSql(CharSequence sql, Map args) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (D) api.findWithNativeSql(sql, args)
+        currentHibernateStaticApi().findWithNativeSql(sql, args)
     }
 
     /**
      * Finds all objects for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
+     * Use this method (not {@code findAll}) when you need raw SQL rather than HQL.
      *
      * @param sql The native SQL query
      * @return The matching objects
@@ -79,8 +79,7 @@ trait HibernateEntity<D> extends GormEntity<D> {
      */
     @Generated
     static List<D> withAllSql(CharSequence sql) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (List<D>) api.findAllWithNativeSql(sql, Collections.emptyMap())
+        currentHibernateStaticApi().findAllWithNativeSql(sql, Collections.emptyMap())
     }
 
     /**
@@ -94,8 +93,92 @@ trait HibernateEntity<D> extends GormEntity<D> {
      */
     @Generated
     static List<D> withAllSql(CharSequence sql, Map args) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (List<D>) api.findAllWithNativeSql(sql, args)
+        currentHibernateStaticApi().findAllWithNativeSql(sql, args)
+    }
+
+    /**
+     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
+     * Use this method (not {@code findAll}) when you need raw SQL rather than HQL.
+     *
+     * @param sql The native SQL query
+     * @return The matching objects
+     */
+    @Generated
+    static List<D> findAllWithNativeSql(CharSequence sql) {
+        currentHibernateStaticApi().findAllWithNativeSql(sql, Collections.emptyMap())
+    }
+
+    /**
+     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
+     * Use this method (not {@code find}) when you need raw SQL rather than HQL.
+     *
+     * @param sql The native SQL query
+     * @return The entity
+     */
+    @Generated
+    static D findWithNativeSql(CharSequence sql) {
+        currentHibernateStaticApi().findWithNativeSql(sql, Collections.emptyMap())
+    }
+
+    /**
+     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
+     *
+     * @param sql  The native SQL query
+     * @param args Pagination/query settings (max, offset, cache, etc.)
+     * @return The matching objects
+     */
+    @Generated
+    static List<D> findAllWithNativeSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findAllWithNativeSql(sql, args)
+    }
+
+    /**
+     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
+     *
+     * @param sql  The native SQL query
+     * @param args Pagination/query settings (max, offset, cache, etc.)
+     * @return The entity
+     */
+    @Generated
+    static D findWithNativeSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findWithNativeSql(sql, args)
+    }
+
+    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence)} — native SQL is distinct from HQL. */
+    @Deprecated
+    @Generated
+    static List<D> findAllWithSql(CharSequence sql) {
+        currentHibernateStaticApi().findAllWithNativeSql(sql, Collections.emptyMap())
+    }
+
+    /** @deprecated Use {@link #findWithNativeSql(CharSequence)} — native SQL is distinct from HQL. */
+    @Deprecated
+    @Generated
+    static D findWithSql(CharSequence sql) {
+        currentHibernateStaticApi().findWithNativeSql(sql, Collections.emptyMap())
+    }
+
+    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
+    @Deprecated
+    @Generated
+    static List<D> findAllWithSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findAllWithNativeSql(sql, args)
+    }
+
+    /** @deprecated Use {@link #findWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
+    @Deprecated
+    @Generated
+    static D findWithSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findWithNativeSql(sql, args)
+    }
+
+    @Generated
+    private static HibernateGormStaticApi currentHibernateStaticApi() {
+        (HibernateGormStaticApi) GormEnhancer.findStaticApi(this)
     }
 
     /**
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
index b77b7e39c4..c2059f4949 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
@@ -283,6 +283,18 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         doListInternal(query, [:], [], args, true)
     }
 
+    /** @deprecated Use {@link #findWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
+    @Deprecated
+    D findWithSql(CharSequence sql, Map args = Collections.emptyMap()) {
+        findWithNativeSql(sql, args)
+    }
+
+    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
+    @Deprecated
+    List<D> findAllWithSql(CharSequence query, Map args = Collections.emptyMap()) {
+        findAllWithNativeSql(query, args)
+    }
+
     // The single-argument CharSequence overloads accept a plain String (executed as written, as
     // on Hibernate 5) or a Groovy GString. A GString is never interpolated into the query text:
     // HqlQueryContext expands every ${value} into a bound named parameter (see
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
index 25f00bde10..4fd203642e 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
@@ -34,10 +34,18 @@ class HibernateEntityTraitGeneratedSpec extends Specification {
     void "test that all HibernateEntity trait methods are marked as Generated"() {
         // Unfortunately static methods have to check directly one by one
         expect:
-        Club.getMethod('withAllSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('withSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('withAllSql', CharSequence, Map).isAnnotationPresent(Generated)
         Club.getMethod('withSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('withAllSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('withAllSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('findWithNativeSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('findWithNativeSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('findAllWithNativeSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('findAllWithNativeSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('findAllWithSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('findWithSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('findAllWithSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('findWithSql', CharSequence, Map).isAnnotationPresent(Generated)
     }
 
 }
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
index bc9843132a..250e87470d 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
@@ -739,6 +739,28 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         result?.name == 'Arsenal'
     }
 
+    void "test deprecated findAllWithSql delegates to findAllWithNativeSql"() {
+        given:
+        setupTestData()
+
+        when:"The deprecated name still works"
+        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
+
+        then:
+        results.size() == 3
+    }
+
+    void "test deprecated findWithSql delegates to findWithNativeSql"() {
+        given:
+        setupTestData()
+
+        when:"The deprecated name still works"
+        Club result = Club.findWithSql("select * from club c where c.name = 'Arsenal'")
+
+        then:
+        result?.name == 'Arsenal'
+    }
+
     void "test sql query with gstring parameters"() {
         given:
         setupTestData()


(grails-core) 01/05: Replace find*WithSql/find*WithNativeSql with withSql/withAllSql in HibernateEntity

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 2d12e77021e0438b97fe552eb4f60778f4c921c8
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Jun 24 16:27:23 2026 -0500

    Replace find*WithSql/find*WithNativeSql with withSql/withAllSql in HibernateEntity
    
    Clean-break rename agreed in weekly meeting: HibernateEntity (H7) now exposes only
    withSql(CharSequence) / withSql(CharSequence, Map) and withAllSql(CharSequence) /
    withAllSql(CharSequence, Map).  The old findWithNativeSql / findAllWithNativeSql
    primary methods and the deprecated findWithSql / findAllWithSql aliases are all
    removed from the trait and from HibernateGormStaticApi (H7).
    
    In H5 the new withSql/withAllSql methods are added and the existing findWithSql /
    findAllWithSql methods are deprecated pointing to the new names; this keeps H5
    backward-compatible while aligning the public API.
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 .../grails/orm/hibernate/HibernateEntity.groovy    | 76 ++++++++++++++++------
 .../tests/HibernateEntityTraitGeneratedSpec.groovy |  4 ++
 .../groovy/grails/gorm/tests/SqlQuerySpec.groovy   |  6 +-
 .../grails/gorm/hibernate/HibernateEntity.groovy   | 68 ++++++-------------
 .../orm/hibernate/HibernateGormStaticApi.groovy    | 12 ----
 .../tests/HibernateEntityTraitGeneratedSpec.groovy |  8 +--
 .../groovy/grails/gorm/tests/SqlQuerySpec.groovy   |  6 +-
 .../hibernate/HibernateGormStaticApiSpec.groovy    | 21 ++----
 8 files changed, 94 insertions(+), 107 deletions(-)

diff --git a/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy b/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy
index 555a69c061..1a2380b23e 100644
--- a/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy
+++ b/grails-data-hibernate5/core/src/main/groovy/grails/orm/hibernate/HibernateEntity.groovy
@@ -36,47 +36,83 @@ import org.grails.orm.hibernate.AbstractHibernateGormStaticApi
 trait HibernateEntity<D> extends GormEntity<D> {
 
     /**
-     * Finds all objects for the given string-based query
+     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @param sql The query
-     *
-     * @return The object
+     * @param sql The native SQL query
+     * @return The entity, or {@code null} if none matched
+     * @since 8.0
      */
     @Generated
-    static List<D> findAllWithSql(CharSequence sql) {
-        currentHibernateStaticApi().findAllWithSql(sql, Collections.emptyMap())
+    static D withSql(CharSequence sql) {
+        currentHibernateStaticApi().findWithSql(sql, Collections.emptyMap())
     }
 
     /**
-     * Finds an entity for the given SQL query
+     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @param sql The sql query
-     * @return The entity
+     * @param sql  The native SQL query
+     * @param args Pagination/query settings (max, offset, cache, etc.)
+     * @return The entity, or {@code null} if none matched
+     * @since 8.0
      */
     @Generated
-    static D findWithSql(CharSequence sql) {
-        currentHibernateStaticApi().findWithSql(sql, Collections.emptyMap())
+    static D withSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findWithSql(sql, args)
     }
 
     /**
-     * Finds all objects for the given string-based query
-     *
-     * @param sql The query
+     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @return The object
+     * @param sql The native SQL query
+     * @return The matching objects
+     * @since 8.0
      */
     @Generated
-    static List<D> findAllWithSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findAllWithSql(sql, args)
+    static List<D> withAllSql(CharSequence sql) {
+        currentHibernateStaticApi().findAllWithSql(sql, Collections.emptyMap())
     }
 
     /**
-     * Finds an entity for the given SQL query
+     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @param sql The sql query
-     * @return The entity
+     * @param sql  The native SQL query
+     * @param args Pagination/query settings (max, offset, cache, etc.)
+     * @return The matching objects
+     * @since 8.0
      */
     @Generated
+    static List<D> withAllSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findAllWithSql(sql, args)
+    }
+
+    /** @deprecated Use {@link #withAllSql(CharSequence)} */
+    @Deprecated
+    @Generated
+    static List<D> findAllWithSql(CharSequence sql) {
+        currentHibernateStaticApi().findAllWithSql(sql, Collections.emptyMap())
+    }
+
+    /** @deprecated Use {@link #withSql(CharSequence)} */
+    @Deprecated
+    @Generated
+    static D findWithSql(CharSequence sql) {
+        currentHibernateStaticApi().findWithSql(sql, Collections.emptyMap())
+    }
+
+    /** @deprecated Use {@link #withAllSql(CharSequence, Map)} */
+    @Deprecated
+    @Generated
+    static List<D> findAllWithSql(CharSequence sql, Map args) {
+        currentHibernateStaticApi().findAllWithSql(sql, args)
+    }
+
+    /** @deprecated Use {@link #withSql(CharSequence, Map)} */
+    @Deprecated
+    @Generated
     static D findWithSql(CharSequence sql, Map args) {
         currentHibernateStaticApi().findWithSql(sql, args)
     }
diff --git a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
index 93d37b4e78..e4fd4c4f2c 100644
--- a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
+++ b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
@@ -34,6 +34,10 @@ class HibernateEntityTraitGeneratedSpec extends Specification {
     void "test that all HibernateEntity trait methods are marked as Generated"() {
         // Unfortunately static methods have to check directly one by one
         expect:
+        Club.getMethod('withAllSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('withSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('withAllSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('withSql', CharSequence, Map).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findWithSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithSql', CharSequence, Map).isAnnotationPresent(Generated)
diff --git a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
index d7a69c7b28..c30bb93c4b 100644
--- a/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
+++ b/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
@@ -41,7 +41,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String name = "Arsenal"
-        Club c = Club.findWithSql("select * from club c where c.name = $name")
+        Club c = Club.withSql("select * from club c where c.name = $name")
 
         then:"The results are correct"
         c != null
@@ -55,7 +55,7 @@ class SqlQuerySpec extends Specification {
         setupTestData()
 
         when:"Some test data is saved"
-        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
+        List<Club> results = Club.withAllSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -69,7 +69,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.findAllWithSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.withAllSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2
diff --git a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
index 063eae3927..5a804135e4 100644
--- a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
@@ -41,93 +41,63 @@ import org.grails.orm.hibernate.HibernateGormStaticApi
 trait HibernateEntity<D> extends GormEntity<D> {
 
     /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
-     * Use this method (not {@code findAll}) when you need raw SQL rather than HQL.
      *
      * @param sql The native SQL query
-     * @return The matching objects
+     * @return The entity, or {@code null} if none matched
+     * @since 8.0
      */
     @Generated
-    static List<D> findAllWithNativeSql(CharSequence sql) {
+    static D withSql(CharSequence sql) {
         HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (List<D>) api.findAllWithNativeSql(sql, Collections.emptyMap())
+        return (D) api.findWithNativeSql(sql, Collections.emptyMap())
     }
 
     /**
      * Finds an entity for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
-     * Use this method (not {@code find}) when you need raw SQL rather than HQL.
      *
-     * @param sql The native SQL query
-     * @return The entity
+     * @param sql  The native SQL query
+     * @param args Pagination/query settings (max, offset, cache, etc.)
+     * @return The entity, or {@code null} if none matched
+     * @since 8.0
      */
     @Generated
-    static D findWithNativeSql(CharSequence sql) {
+    static D withSql(CharSequence sql, Map args) {
         HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (D) api.findWithNativeSql(sql, Collections.emptyMap())
+        return (D) api.findWithNativeSql(sql, args)
     }
 
     /**
      * Finds all objects for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @param sql  The native SQL query
-     * @param args Pagination/query settings (max, offset, cache, etc.)
+     * @param sql The native SQL query
      * @return The matching objects
+     * @since 8.0
      */
     @Generated
-    static List<D> findAllWithNativeSql(CharSequence sql, Map args) {
+    static List<D> withAllSql(CharSequence sql) {
         HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (List<D>) api.findAllWithNativeSql(sql, args)
+        return (List<D>) api.findAllWithNativeSql(sql, Collections.emptyMap())
     }
 
     /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
      *
      * @param sql  The native SQL query
      * @param args Pagination/query settings (max, offset, cache, etc.)
-     * @return The entity
+     * @return The matching objects
+     * @since 8.0
      */
     @Generated
-    static D findWithNativeSql(CharSequence sql, Map args) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (D) api.findWithNativeSql(sql, args)
-    }
-
-    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static List<D> findAllWithSql(CharSequence sql) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (List<D>) api.findAllWithNativeSql(sql, Collections.emptyMap())
-    }
-
-    /** @deprecated Use {@link #findWithNativeSql(CharSequence)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static D findWithSql(CharSequence sql) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (D) api.findWithNativeSql(sql, Collections.emptyMap())
-    }
-
-    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static List<D> findAllWithSql(CharSequence sql, Map args) {
+    static List<D> withAllSql(CharSequence sql, Map args) {
         HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
         return (List<D>) api.findAllWithNativeSql(sql, args)
     }
 
-    /** @deprecated Use {@link #findWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static D findWithSql(CharSequence sql, Map args) {
-        HibernateGormStaticApi<D> api = (HibernateGormStaticApi<D>) GormEnhancer.findStaticApi(this)
-        return (D) api.findWithNativeSql(sql, args)
-    }
-
     /**
      * Overrides {@link GormEntity#addTo} to fix "Found two representations of same collection"
      * in Hibernate 7.
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
index c2059f4949..b77b7e39c4 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
@@ -283,18 +283,6 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         doListInternal(query, [:], [], args, true)
     }
 
-    /** @deprecated Use {@link #findWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    D findWithSql(CharSequence sql, Map args = Collections.emptyMap()) {
-        findWithNativeSql(sql, args)
-    }
-
-    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    List<D> findAllWithSql(CharSequence query, Map args = Collections.emptyMap()) {
-        findAllWithNativeSql(query, args)
-    }
-
     // The single-argument CharSequence overloads accept a plain String (executed as written, as
     // on Hibernate 5) or a Groovy GString. A GString is never interpolated into the query text:
     // HqlQueryContext expands every ${value} into a bound named parameter (see
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
index 93d37b4e78..25f00bde10 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
@@ -34,10 +34,10 @@ class HibernateEntityTraitGeneratedSpec extends Specification {
     void "test that all HibernateEntity trait methods are marked as Generated"() {
         // Unfortunately static methods have to check directly one by one
         expect:
-        Club.getMethod('findAllWithSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('findWithSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('findAllWithSql', CharSequence, Map).isAnnotationPresent(Generated)
-        Club.getMethod('findWithSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('withAllSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('withSql', CharSequence).isAnnotationPresent(Generated)
+        Club.getMethod('withAllSql', CharSequence, Map).isAnnotationPresent(Generated)
+        Club.getMethod('withSql', CharSequence, Map).isAnnotationPresent(Generated)
     }
 
 }
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
index d7a69c7b28..c30bb93c4b 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
@@ -41,7 +41,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String name = "Arsenal"
-        Club c = Club.findWithSql("select * from club c where c.name = $name")
+        Club c = Club.withSql("select * from club c where c.name = $name")
 
         then:"The results are correct"
         c != null
@@ -55,7 +55,7 @@ class SqlQuerySpec extends Specification {
         setupTestData()
 
         when:"Some test data is saved"
-        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
+        List<Club> results = Club.withAllSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -69,7 +69,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.findAllWithSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.withAllSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
index cec46c9253..bc9843132a 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
@@ -719,7 +719,7 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         setupTestData()
 
         when:"A static native SQL query with no user input"
-        List<Club> results = Club.findAllWithNativeSql("select * from club c order by c.name")
+        List<Club> results = Club.withAllSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -728,23 +728,12 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         club.name == 'Arsenal'
     }
 
-    void "test deprecated findAllWithSql delegates to findAllWithNativeSql"() {
+    void "test withSql returns a single result"() {
         given:
         setupTestData()
 
-        when:"The deprecated name still works"
-        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
-
-        then:
-        results.size() == 3
-    }
-
-    void "test deprecated findWithSql delegates to findWithNativeSql"() {
-        given:
-        setupTestData()
-
-        when:"The deprecated name still works"
-        Club result = Club.findWithSql("select * from club c where c.name = 'Arsenal'")
+        when:"A native SQL query for a single entity"
+        Club result = Club.withSql("select * from club c where c.name = 'Arsenal'")
 
         then:
         result?.name == 'Arsenal'
@@ -756,7 +745,7 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.findAllWithNativeSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.withAllSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2


(grails-core) 04/05: Align H7 HibernateEntity public API with H5: findWithSql/findAllWithSql

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 96e732d705ffb2a248a0f93a5641e3302908359e
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Jun 24 16:57:12 2026 -0500

    Align H7 HibernateEntity public API with H5: findWithSql/findAllWithSql
    
    H7's HibernateEntity now exposes the same public method names as H5
    (findWithSql / findAllWithSql) while delegating internally to
    HibernateGormStaticApi.findWithNativeSql / findAllWithNativeSql.
    No deprecated aliases, no findWithNativeSql on the trait surface.
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 .../grails/gorm/hibernate/HibernateEntity.groovy   | 52 +++++-----------------
 .../tests/HibernateEntityTraitGeneratedSpec.groovy |  4 --
 .../hibernate/HibernateGormStaticApiSpec.groovy    | 26 +----------
 3 files changed, 13 insertions(+), 69 deletions(-)

diff --git a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
index 43dac27c2d..edcdca57b8 100644
--- a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
@@ -41,81 +41,51 @@ import org.grails.orm.hibernate.HibernateGormStaticApi
 trait HibernateEntity<D> extends GormEntity<D> {
 
     /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * Finds all objects for the given SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
-     * Use this method (not {@code findAll}) when you need raw SQL rather than HQL.
      *
-     * @param sql The native SQL query
+     * @param sql The SQL query
      * @return The matching objects
      */
     @Generated
-    static List<D> findAllWithNativeSql(CharSequence sql) {
+    static List<D> findAllWithSql(CharSequence sql) {
         currentHibernateStaticApi().findAllWithNativeSql(sql, Collections.emptyMap())
     }
 
     /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * Finds an entity for the given SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
-     * Use this method (not {@code find}) when you need raw SQL rather than HQL.
      *
-     * @param sql The native SQL query
+     * @param sql The SQL query
      * @return The entity
      */
     @Generated
-    static D findWithNativeSql(CharSequence sql) {
+    static D findWithSql(CharSequence sql) {
         currentHibernateStaticApi().findWithNativeSql(sql, Collections.emptyMap())
     }
 
     /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
+     * Finds all objects for the given SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @param sql  The native SQL query
+     * @param sql  The SQL query
      * @param args Pagination/query settings (max, offset, cache, etc.)
      * @return The matching objects
      */
     @Generated
-    static List<D> findAllWithNativeSql(CharSequence sql, Map args) {
+    static List<D> findAllWithSql(CharSequence sql, Map args) {
         currentHibernateStaticApi().findAllWithNativeSql(sql, args)
     }
 
     /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
+     * Finds an entity for the given SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
      *
-     * @param sql  The native SQL query
+     * @param sql  The SQL query
      * @param args Pagination/query settings (max, offset, cache, etc.)
      * @return The entity
      */
     @Generated
-    static D findWithNativeSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findWithNativeSql(sql, args)
-    }
-
-    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static List<D> findAllWithSql(CharSequence sql) {
-        currentHibernateStaticApi().findAllWithNativeSql(sql, Collections.emptyMap())
-    }
-
-    /** @deprecated Use {@link #findWithNativeSql(CharSequence)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static D findWithSql(CharSequence sql) {
-        currentHibernateStaticApi().findWithNativeSql(sql, Collections.emptyMap())
-    }
-
-    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
-    static List<D> findAllWithSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findAllWithNativeSql(sql, args)
-    }
-
-    /** @deprecated Use {@link #findWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    @Generated
     static D findWithSql(CharSequence sql, Map args) {
         currentHibernateStaticApi().findWithNativeSql(sql, args)
     }
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
index d762c36209..93d37b4e78 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
@@ -34,10 +34,6 @@ class HibernateEntityTraitGeneratedSpec extends Specification {
     void "test that all HibernateEntity trait methods are marked as Generated"() {
         // Unfortunately static methods have to check directly one by one
         expect:
-        Club.getMethod('findWithNativeSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('findWithNativeSql', CharSequence, Map).isAnnotationPresent(Generated)
-        Club.getMethod('findAllWithNativeSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('findAllWithNativeSql', CharSequence, Map).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findWithSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithSql', CharSequence, Map).isAnnotationPresent(Generated)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
index cec46c9253..8b64a33847 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
@@ -719,7 +719,7 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         setupTestData()
 
         when:"A static native SQL query with no user input"
-        List<Club> results = Club.findAllWithNativeSql("select * from club c order by c.name")
+        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -728,35 +728,13 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         club.name == 'Arsenal'
     }
 
-    void "test deprecated findAllWithSql delegates to findAllWithNativeSql"() {
-        given:
-        setupTestData()
-
-        when:"The deprecated name still works"
-        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
-
-        then:
-        results.size() == 3
-    }
-
-    void "test deprecated findWithSql delegates to findWithNativeSql"() {
-        given:
-        setupTestData()
-
-        when:"The deprecated name still works"
-        Club result = Club.findWithSql("select * from club c where c.name = 'Arsenal'")
-
-        then:
-        result?.name == 'Arsenal'
-    }
-
     void "test sql query with gstring parameters"() {
         given:
         setupTestData()
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.findAllWithNativeSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.findAllWithSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2


(grails-core) 03/05: Remove withSql/withAllSql from HibernateEntity H7 — no new public API

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 64e141ad5f78c9b48cd79eb5fe8977948f6855e3
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Jun 24 16:41:14 2026 -0500

    Remove withSql/withAllSql from HibernateEntity H7 — no new public API
    
    The withSql/withAllSql additions are reverted. H7 HibernateEntity now exposes
    exactly what it had before: findWithNativeSql/findAllWithNativeSql as the primary
    methods and deprecated findWithSql/findAllWithSql as backward-compat aliases,
    all delegating through the private currentHibernateStaticApi() helper.
    
    Tests updated to use findWithNativeSql/findAllWithNativeSql and
    findWithSql/findAllWithSql accordingly.
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 .../grails/gorm/hibernate/HibernateEntity.groovy   | 56 ----------------------
 .../tests/HibernateEntityTraitGeneratedSpec.groovy |  4 --
 .../groovy/grails/gorm/tests/SqlQuerySpec.groovy   |  6 +--
 .../hibernate/HibernateGormStaticApiSpec.groovy    | 15 +-----
 4 files changed, 5 insertions(+), 76 deletions(-)

diff --git a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
index fee53485e7..43dac27c2d 100644
--- a/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/grails/gorm/hibernate/HibernateEntity.groovy
@@ -40,62 +40,6 @@ import org.grails.orm.hibernate.HibernateGormStaticApi
 @CompileStatic
 trait HibernateEntity<D> extends GormEntity<D> {
 
-    /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
-     * Use this method (not {@code find}) when you need raw SQL rather than HQL.
-     *
-     * @param sql The native SQL query
-     * @return The entity
-     * @since 8.0
-     */
-    @Generated
-    static D withSql(CharSequence sql) {
-        currentHibernateStaticApi().findWithNativeSql(sql, Collections.emptyMap())
-    }
-
-    /**
-     * Finds an entity for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
-     *
-     * @param sql  The native SQL query
-     * @param args Pagination/query settings (max, offset, cache, etc.)
-     * @return The entity
-     * @since 8.0
-     */
-    @Generated
-    static D withSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findWithNativeSql(sql, args)
-    }
-
-    /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
-     * Use this method (not {@code findAll}) when you need raw SQL rather than HQL.
-     *
-     * @param sql The native SQL query
-     * @return The matching objects
-     * @since 8.0
-     */
-    @Generated
-    static List<D> withAllSql(CharSequence sql) {
-        currentHibernateStaticApi().findAllWithNativeSql(sql, Collections.emptyMap())
-    }
-
-    /**
-     * Finds all objects for the given native SQL query. Pass a GString to have interpolated
-     * values safely bound as named parameters rather than interpolated into the query string.
-     *
-     * @param sql  The native SQL query
-     * @param args Pagination/query settings (max, offset, cache, etc.)
-     * @return The matching objects
-     * @since 8.0
-     */
-    @Generated
-    static List<D> withAllSql(CharSequence sql, Map args) {
-        currentHibernateStaticApi().findAllWithNativeSql(sql, args)
-    }
-
     /**
      * Finds all objects for the given native SQL query. Pass a GString to have interpolated
      * values safely bound as named parameters rather than interpolated into the query string.
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
index 4fd203642e..d762c36209 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/HibernateEntityTraitGeneratedSpec.groovy
@@ -34,10 +34,6 @@ class HibernateEntityTraitGeneratedSpec extends Specification {
     void "test that all HibernateEntity trait methods are marked as Generated"() {
         // Unfortunately static methods have to check directly one by one
         expect:
-        Club.getMethod('withSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('withSql', CharSequence, Map).isAnnotationPresent(Generated)
-        Club.getMethod('withAllSql', CharSequence).isAnnotationPresent(Generated)
-        Club.getMethod('withAllSql', CharSequence, Map).isAnnotationPresent(Generated)
         Club.getMethod('findWithNativeSql', CharSequence).isAnnotationPresent(Generated)
         Club.getMethod('findWithNativeSql', CharSequence, Map).isAnnotationPresent(Generated)
         Club.getMethod('findAllWithNativeSql', CharSequence).isAnnotationPresent(Generated)
diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
index c30bb93c4b..d7a69c7b28 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/SqlQuerySpec.groovy
@@ -41,7 +41,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String name = "Arsenal"
-        Club c = Club.withSql("select * from club c where c.name = $name")
+        Club c = Club.findWithSql("select * from club c where c.name = $name")
 
         then:"The results are correct"
         c != null
@@ -55,7 +55,7 @@ class SqlQuerySpec extends Specification {
         setupTestData()
 
         when:"Some test data is saved"
-        List<Club> results = Club.withAllSql("select * from club c order by c.name")
+        List<Club> results = Club.findAllWithSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -69,7 +69,7 @@ class SqlQuerySpec extends Specification {
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.withAllSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.findAllWithSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
index 250e87470d..cec46c9253 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
@@ -719,7 +719,7 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         setupTestData()
 
         when:"A static native SQL query with no user input"
-        List<Club> results = Club.withAllSql("select * from club c order by c.name")
+        List<Club> results = Club.findAllWithNativeSql("select * from club c order by c.name")
 
         then:"The results are correct"
         results.size() == 3
@@ -728,17 +728,6 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         club.name == 'Arsenal'
     }
 
-    void "test withSql returns a single result"() {
-        given:
-        setupTestData()
-
-        when:"A native SQL query for a single entity"
-        Club result = Club.withSql("select * from club c where c.name = 'Arsenal'")
-
-        then:
-        result?.name == 'Arsenal'
-    }
-
     void "test deprecated findAllWithSql delegates to findAllWithNativeSql"() {
         given:
         setupTestData()
@@ -767,7 +756,7 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
 
         when:"Some test data is saved"
         String p = "%l%"
-        List<Club> results = Club.withAllSql("select * from club c where c.name like $p order by c.name")
+        List<Club> results = Club.findAllWithNativeSql("select * from club c where c.name like $p order by c.name")
 
         then:"The results are correct"
         results.size() == 2


(grails-core) 05/05: Remove deprecated findWithSql/findAllWithSql from HibernateGormStaticApi

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 543c691e42f9d43088d3d139ec504b00b0027ca1
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Jun 24 17:00:18 2026 -0500

    Remove deprecated findWithSql/findAllWithSql from HibernateGormStaticApi
    
    These aliases are no longer needed: the HibernateEntity trait now exposes
    findWithSql/findAllWithSql directly, delegating to findWithNativeSql/
    findAllWithNativeSql which remain the implementation in HibernateGormStaticApi.
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 .../org/grails/orm/hibernate/HibernateGormStaticApi.groovy   | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
index c2059f4949..b77b7e39c4 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy
@@ -283,18 +283,6 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         doListInternal(query, [:], [], args, true)
     }
 
-    /** @deprecated Use {@link #findWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    D findWithSql(CharSequence sql, Map args = Collections.emptyMap()) {
-        findWithNativeSql(sql, args)
-    }
-
-    /** @deprecated Use {@link #findAllWithNativeSql(CharSequence, Map)} — native SQL is distinct from HQL. */
-    @Deprecated
-    List<D> findAllWithSql(CharSequence query, Map args = Collections.emptyMap()) {
-        findAllWithNativeSql(query, args)
-    }
-
     // The single-argument CharSequence overloads accept a plain String (executed as written, as
     // on Hibernate 5) or a Groovy GString. A GString is never interpolated into the query text:
     // HqlQueryContext expands every ${value} into a bound named parameter (see