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:40 UTC
(grails-core) 04/05: Align H7 HibernateEntity public API with H5: findWithSql/findAllWithSql
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