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/10/04 00:28:23 UTC

(grails-core) 02/08: test: restore the Hibernate 5 contract in SaveWithInvalidEntitySpec

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

borinquenkid pushed a commit to branch 9.0.x-h7-improvement-phase1
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit e106e068c8b31b7a3af7f7dda4eb52698a34040d
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sat Oct 3 16:50:41 2026 -0500

    test: restore the Hibernate 5 contract in SaveWithInvalidEntitySpec
    
    The Hibernate 7 copy was @Ignore'd and weakened to assert only A.count() == 1
    because of a NullPointerException tracked in issue 10604. That failure no
    longer occurs, and the original assertions (an exception is thrown, the
    entity has errors, and field1 reports a field error) pass on Hibernate 7.
    
    Co-Authored-By: Claude Sonnet 5.5 <no...@anthropic.com>
---
 .../validation/SaveWithInvalidEntitySpec.groovy    | 23 +++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/validation/SaveWithInvalidEntitySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/validation/SaveWithInvalidEntitySpec.groovy
index dacc15cf81..9179e349c4 100644
--- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/validation/SaveWithInvalidEntitySpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/validation/SaveWithInvalidEntitySpec.groovy
@@ -22,7 +22,6 @@ import grails.gorm.annotation.Entity
 import grails.gorm.transactions.Rollback
 import org.grails.orm.hibernate.HibernateDatastore
 import spock.lang.AutoCleanup
-import spock.lang.Ignore
 import spock.lang.Issue
 import spock.lang.Shared
 import spock.lang.Specification
@@ -34,20 +33,22 @@ class SaveWithInvalidEntitySpec extends Specification {
 
     @Shared @AutoCleanup HibernateDatastore hibernateDatastore = new HibernateDatastore(A, B)
 
-    /**
-     * This currently fails with a NPE. See explanation https://github.com/apache/grails-core/issues/14616#issuecomment-298943022
-     */
     @Rollback
-    @Ignore
-    @Issue('https://github.com/apache/grails-core/issues/10604')
+    @Issue('https://github.com/apache/grails-core/issues/14616')
     void "test save with an invalid entity"() {
+        given:
+        def b = new B(field2: "test")
+        def a = new A(b: b)
+
         when:
-        hibernateDatastore.currentSession.persist(new A(b:new B(field2: "test")))
+        hibernateDatastore.currentSession.persist(a)
         hibernateDatastore.currentSession.flush()
 
         then:
-        A.count() == 1
-
+        Exception e = thrown()
+        e.getClass().simpleName in ['EntityActionVetoException', 'HibernateSystemException', 'IllegalStateException', 'ConstraintViolationException']
+        b.hasErrors()
+        b.errors.hasFieldErrors('field1')
     }
 }
 
@@ -59,4 +60,8 @@ class A {
 class B {
     String field1
     String field2
+
+    static constraints = {
+        field1 nullable: false
+    }
 }