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 e24cc7f9ddcf54b293db4bb04d675a081b1b014f Author: Walter Duque de Estrada <[email protected]> AuthorDate: Tue Mar 3 21:06:34 2026 -0600 fix FindByExample --- grails-data-hibernate7/README.md | 1 - .../orm/hibernate/HibernateGormStaticApi.groovy | 10 ----- .../hibernate/HibernateGormStaticApiSpec.groovy | 50 +++++++++++++++++++--- .../testing/tck/tests/FindByExampleSpec.groovy | 1 - 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/grails-data-hibernate7/README.md b/grails-data-hibernate7/README.md index 9a6d018357..88a96fc11c 100644 --- a/grails-data-hibernate7/README.md +++ b/grails-data-hibernate7/README.md @@ -34,7 +34,6 @@ These tests live in `grails-datamapping-tck` and are deliberately excluded for H | `NamedQuerySpec` | 38 | `@IgnoreIf(hibernate7.gorm.suite == true)` | Named query support not yet ported to Hibernate 7 | | `GroovyProxySpec` | 5 | `@IgnoreIf(hibernate5/6/7.gorm.suite)` | Groovy proxy support requires `ByteBuddyGroovyProxyFactory`; excluded for all Hibernate suites | | `OptimisticLockingSpec` | 3 | `@IgnoreIf` (detects Hibernate datastore on classpath) | Hibernate has its own `Hibernate7OptimisticLockingSpec` replacement | -| `FindByExampleSpec` | 2 | `@IgnoreIf(hibernate6/7.gorm.suite == true)` | Find-by-example not implemented for Hibernate 7 | | `UpdateWithProxyPresentSpec` | 2 | `@IgnoreIf(hibernate7.gorm.suite == true)` | Proxy update behaviour differs in Hibernate 7 | | `RLikeSpec` | 1 | `@IgnoreIf(hibernate7.gorm.suite == true)` | `rlike` not supported in HQL / H2 in Hibernate 7 mode | | `DirtyCheckingAfterListenerSpec` | 1 | `@PendingFeatureIf(!hibernate5/6/mongodb)` | `test state change from listener update the object` — pending for 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 721525b217..69e3fb41f0 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 @@ -297,16 +297,6 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> { - @Override - D find(D exampleObject, Map args) { - throw new UnsupportedOperationException("not yet") - } - - @Override - List<D> findAll(D exampleObject, Map args) { - throw new UnsupportedOperationException("Example is not supported but maybe in the future") - } - @Override List<D> findAllWhere(Map queryMap, Map args) { if (!queryMap) return null 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 1aea214b14..5b9eb319d7 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 @@ -292,12 +292,30 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec { found != null } - void "Test find with example throws exception"() { + void "Test find with example returns matching instance"() { + given: + new HibernateGormStaticApiEntity(name: "alpha").save(failOnError: true) + new HibernateGormStaticApiEntity(name: "beta").save(flush: true, failOnError: true) + manager.session.clear() + when: - HibernateGormStaticApiEntity.find(new HibernateGormStaticApiEntity()) + def result = HibernateGormStaticApiEntity.find(new HibernateGormStaticApiEntity(name: "beta")) then: - thrown(UnsupportedOperationException) + result != null + result.name == "beta" + } + + void "Test find with example returns null when no match"() { + given: + new HibernateGormStaticApiEntity(name: "alpha").save(flush: true, failOnError: true) + manager.session.clear() + + when: + def result = HibernateGormStaticApiEntity.find(new HibernateGormStaticApiEntity(name: "nonexistent")) + + then: + result == null } void "Test first method"() { @@ -390,12 +408,32 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec { instances.size() == 2 } - void "Test findAll with example throws exception"() { + void "Test findAll with example returns matching instances"() { + given: + new HibernateGormStaticApiEntity(name: "match").save(failOnError: true) + new HibernateGormStaticApiEntity(name: "match").save(failOnError: true) + new HibernateGormStaticApiEntity(name: "other").save(flush: true, failOnError: true) + manager.session.clear() + when: - HibernateGormStaticApiEntity.findAll(new HibernateGormStaticApiEntity()) + def results = HibernateGormStaticApiEntity.findAll(new HibernateGormStaticApiEntity(name: "match")) then: - thrown(UnsupportedOperationException) + results.size() == 2 + results.every { it.name == "match" } + } + + void "Test findAll with empty example returns empty list"() { + given: + new HibernateGormStaticApiEntity(name: "a").save(failOnError: true) + new HibernateGormStaticApiEntity(name: "b").save(flush: true, failOnError: true) + manager.session.clear() + + when: "no non-null properties to constrain on" + def results = HibernateGormStaticApiEntity.findAll(new HibernateGormStaticApiEntity()) + + then: "findAllWhere with empty map returns null (by design guard)" + results == null } void "Test getAll with long varargs"() { diff --git a/grails-datamapping-tck/src/main/groovy/org/apache/grails/data/testing/tck/tests/FindByExampleSpec.groovy b/grails-datamapping-tck/src/main/groovy/org/apache/grails/data/testing/tck/tests/FindByExampleSpec.groovy index 1d7186f0b7..c6552e22f0 100644 --- a/grails-datamapping-tck/src/main/groovy/org/apache/grails/data/testing/tck/tests/FindByExampleSpec.groovy +++ b/grails-datamapping-tck/src/main/groovy/org/apache/grails/data/testing/tck/tests/FindByExampleSpec.groovy @@ -23,7 +23,6 @@ import org.apache.grails.data.testing.tck.base.GrailsDataTckSpec import spock.lang.IgnoreIf -@IgnoreIf({ System.getProperty("hibernate6.gorm.suite") == "true" || System.getProperty("hibernate7.gorm.suite") == "true" }) class FindByExampleSpec extends GrailsDataTckSpec { void setupSpec() {
