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 bd9254d409d2fb90bd5cc916ee64724e04720a3d Author: Walter B Duque de Estrada <[email protected]> AuthorDate: Sat Jan 24 20:46:57 2026 -0600 update progress --- .../validation/SaveWithInvalidEntitySpec.groovy | 3 ++- .../orm/hibernate/GrailsHibernateTemplate.java | 25 +++++++++++++++------- .../validation/SaveWithInvalidEntitySpec.groovy | 13 ++++++++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/grails-data-hibernate6/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy b/grails-data-hibernate6/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy index 39f3a5a166..3ad02530d9 100644 --- a/grails-data-hibernate6/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy +++ b/grails-data-hibernate6/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy @@ -47,7 +47,8 @@ class SaveWithInvalidEntitySpec extends Specification { hibernateDatastore.currentSession.flush() then: - IllegalStateException e = thrown() + Exception e = thrown() + throw new RuntimeException("EXCEPTION: " + e.getClass().getName() + "\nSTACK: " + e.stackTrace.collect { it.toString() }.join("\n")) } } diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/GrailsHibernateTemplate.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/GrailsHibernateTemplate.java index 742af1a6c0..2567e2df10 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/GrailsHibernateTemplate.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/GrailsHibernateTemplate.java @@ -699,20 +699,29 @@ public class GrailsHibernateTemplate implements IHibernateTemplate { return translator.translate("Hibernate operation: " + msg, sql, sqlException); } - public void persist(Object o) { - sessionFactory.getCurrentSession().persist(o); + public void persist(final Object entity) throws DataAccessException { + doExecute(session -> { + session.persist(entity); + return null; + }, true); } - public Object merge(Object o) { - return sessionFactory.getCurrentSession().merge(o); + public Object merge(final Object entity) throws DataAccessException { + return doExecute(session -> session.merge(entity), true); } - public void flush() { - sessionFactory.getCurrentSession().flush(); + public void flush() throws DataAccessException { + doExecute(session -> { + session.flush(); + return null; + }, true); } - public void clear() { - sessionFactory.getCurrentSession().clear(); + public void clear() throws DataAccessException { + doExecute(session -> { + session.clear(); + return null; + }, true); } public void deleteAll(final Collection<?> objects) { diff --git a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy index 39f3a5a166..a628f67fb9 100644 --- a/grails-data-hibernate7/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/grails/gorm/specs/validation/SaveWithInvalidEntitySpec.groovy @@ -42,13 +42,20 @@ class SaveWithInvalidEntitySpec extends Specification { @Rollback @Issue('https://github.com/grails/grails-core/issues/10604') 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: - IllegalStateException e = thrown() - + Exception e = thrown() + // In Hibernate 7, a veto results in EntityActionVetoException (translated to HibernateSystemException) + e.getClass().simpleName in ['HibernateSystemException', 'IllegalStateException'] + b.hasErrors() + b.errors.hasFieldErrors('field1') } }
