HHH-13300 Correctly convert Hibernate exceptions to JPA in executeUpdate()
This commit is contained in:
parent
5a1efe883e
commit
634782fef6
|
@ -1614,12 +1614,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();
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.annotations.Immutable;
|
||||
|
@ -24,6 +25,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;
|
||||
|
||||
/**
|
||||
|
@ -61,10 +63,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