JPA에서 transaction 처리 방법

~~~~~java@ 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();}}}~~~~~

~~~~~javaclass MyService2 {@Transactional(noRollbackFor = IllegalArgumentException.class)public void validateAddress(Address address) {// Some validations using daoif (!isValid) {throws new IllegalArgumentException();}}}~~~~~

Friday, 13 November 2015, 03:54
comments powered by Disqus