#1507 - SqlUpdate.execute PersistenceException is not translated into more specific exception (like DuplicateKeyException)

Support for sqlUpdate.executeBatch()
This commit is contained in:
rob bygrave
2018-10-15 22:30:42 +13:00
parent 3eaf47fd70
commit 2646e8c27f
2 changed files with 24 additions and 1 deletions
@@ -69,4 +69,27 @@ public class TestSqlUpdateExceptions extends BaseTestCase {
transaction.commit();
}
}
@Test(expected = DuplicateKeyException.class)
public void duplicateKey_executeBatch() {
UUID id = UUID.randomUUID();
try (Transaction transaction = Ebean.beginTransaction()) {
SqlUpdate sqlUpdate = Ebean.createSqlUpdate(sql);
sqlUpdate.setParameter(1, id);
sqlUpdate.setParameter(2, "hi in batch");
sqlUpdate.setParameter(3, 1);
sqlUpdate.addBatch();
sqlUpdate.setParameter(1, id);
sqlUpdate.setParameter(2, "fail in batch");
sqlUpdate.setParameter(3, 1);
sqlUpdate.addBatch();
int[] ints = sqlUpdate.executeBatch();
transaction.commit();
}
}
}