diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java index cca1c234dd..1b41ac7ef4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java @@ -1590,12 +1590,7 @@ public abstract class AbstractProducedQuery implements QueryImplementor { throw new IllegalArgumentException( e ); } catch ( HibernateException e) { - if ( getProducer().getFactory().getSessionFactoryOptions().isJpaBootstrap() ) { - throw getExceptionConverter().convert( e ); - } - else { - throw e; - } + throw getExceptionConverter().convert( e ); } finally { afterQuery(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableEntityUpdateQueryHandlingModeExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableEntityUpdateQueryHandlingModeExceptionTest.java index 60ed5a7dc8..32412378a2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableEntityUpdateQueryHandlingModeExceptionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableEntityUpdateQueryHandlingModeExceptionTest.java @@ -8,6 +8,8 @@ package org.hibernate.test.annotations.immutable; import java.util.Map; +import javax.persistence.PersistenceException; + import org.hibernate.HibernateException; import org.hibernate.cfg.AvailableSettings; @@ -18,6 +20,7 @@ import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -54,10 +57,14 @@ public class ImmutableEntityUpdateQueryHandlingModeExceptionTest extends BaseNon .setParameter( "name", "N/A" ) .executeUpdate(); } ); - fail("Should throw HibernateException"); + fail("Should throw PersistenceException"); } - catch (HibernateException e) { - assertEquals( "The query: [update Country set name = :name] attempts to update an immutable entity: [Country]", e.getMessage() ); + catch (PersistenceException e) { + assertTrue( e.getCause() instanceof HibernateException ); + assertEquals( + "The query: [update Country set name = :name] attempts to update an immutable entity: [Country]", + e.getCause().getMessage() + ); } doInHibernate( this::sessionFactory, session -> {