@ Transactional(rollbackFor = {RuntimeException.class})
public SomeService {
@ Autowired SomeRepository repository1;
@ Autowired AnotherRepository repository2;
@ Autowired ThirdRepository repository3;
...
@ Transactional(rollbackFor = {RuntimeException.class})
public void SomeMethod(SomeEntity obj, String someNewValue) {
try {
repository1.updateMethod();
repository2.updateMethod();
obj.setValue(someNewValue);
repository3.save(obj);
} catch (Exception ex) {
throw new RuntimeException();
}
}
}
class MyService2 {
@Transactional(noRollbackFor = IllegalArgumentException.class)
public void validateAddress(Address address) {
// Some validations using dao
if (!isValid) {
throws new IllegalArgumentException();
}
}
}