HHH-13300 Test behavior when Query.executeUpdate() throws an exception
This commit is contained in:
parent
4665fd9cd9
commit
5a1efe883e
|
@ -94,6 +94,13 @@ interface ExceptionExpectations {
|
|||
assertThat( e.getCause(), instanceOf( PersistenceException.class ) );
|
||||
assertThat( e.getCause().getCause(), instanceOf( TransactionException.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecuteUpdateWithConstraintViolation(RuntimeException e) {
|
||||
assertThat( e, instanceOf( PersistenceException.class ) );
|
||||
assertThat( e.getCause(), instanceOf( ConstraintViolationException.class ) );
|
||||
assertThat( e.getCause().getCause(), instanceOf( SQLException.class ) );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -160,6 +167,12 @@ interface ExceptionExpectations {
|
|||
public void onTransactionExceptionOnCommit(RuntimeException e) {
|
||||
assertThat( e, instanceOf( TransactionException.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecuteUpdateWithConstraintViolation(RuntimeException e) {
|
||||
assertThat( e, instanceOf( ConstraintViolationException.class ) );
|
||||
assertThat( e.getCause(), instanceOf( SQLException.class ) );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -233,6 +246,13 @@ interface ExceptionExpectations {
|
|||
assertThat( e, instanceOf( PersistenceException.class ) );
|
||||
assertThat( e.getCause(), instanceOf( TransactionException.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecuteUpdateWithConstraintViolation(RuntimeException e) {
|
||||
assertThat( e, instanceOf( PersistenceException.class ) );
|
||||
assertThat( e.getCause(), instanceOf( ConstraintViolationException.class ) );
|
||||
assertThat( e.getCause().getCause(), instanceOf( SQLException.class ) );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -259,4 +279,6 @@ interface ExceptionExpectations {
|
|||
void onTransactionExceptionOnPersistAndMergeAndFlush(RuntimeException e);
|
||||
|
||||
void onTransactionExceptionOnCommit(RuntimeException e);
|
||||
|
||||
void onExecuteUpdateWithConstraintViolation(RuntimeException e);
|
||||
}
|
|
@ -91,6 +91,20 @@ public class QueryExceptionHandlingTest extends BaseExceptionHandlingTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13300")
|
||||
public void testExecuteUpdateWithConstraintViolation() {
|
||||
try {
|
||||
TransactionUtil2.inTransaction( sessionFactory(), s -> {
|
||||
s.createQuery( "update A set id = 1 where id = 2" ).executeUpdate();
|
||||
} );
|
||||
fail( "should have thrown an exception" );
|
||||
}
|
||||
catch (RuntimeException expected) {
|
||||
exceptionExpectations.onExecuteUpdateWithConstraintViolation( expected );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "A")
|
||||
public static class A {
|
||||
@Id
|
||||
|
|
Loading…
Reference in New Issue