@Transactional(rollbackFor = { ServiceException.class }, noRollbackFor={IllegalArgumentException.class})
public void updateUser(User user) throws Exception {
try {
userRepository.save(user);
if (user.getName().isEmpty()) {
throw new IllegalArgumentException("Name must be has characters");
}
if (user.getEmail().equals("admin@gmail.com")) {
throw new ServiceException("Update Admin");
}
} catch (Exception e) {
logger.error(e.getMessage());
throw e;
}
}
Using rollbackFor and noRollbackFor, for rollback or commit.
Continue ...
0 nhận xét:
Đăng nhận xét