@Transactional isn't rolling back the transaction when I'm throwing the exception in a catch block.
@Transactional(rollbackFor = MyException.class)
public void testTransactional2() throws Exception {
try {
dao1.save(entity1);
dao2.save(entity2);
arrayList.get(999999); // intentionally cause an exception
} catch (IndexOutOfBoundsException e) {
throw new MyException(ErrorCode.UNABLE_TO_INSERT, e);
}
}
dao1.save()
and dao2.save()
are both annotated with @Transactional
themselves.
When I check the database, I see both the entities are persisted.