HHH-13300 Correctly convert Hibernate exceptions to JPA in executeUpdate()
(cherry picked from commit 634782fef6
)
This commit is contained in:
parent
a93a5183ba
commit
bf85bfcf99
|
@ -1590,12 +1590,7 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
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();
|
||||
|
|
|
@ -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 -> {
|
||||
|
|
Loading…
Reference in New Issue