Last active
July 9, 2020 02:31
-
-
Save anny0739/ed3b94bcf2b42ccb611b484b4781d43f to your computer and use it in GitHub Desktop.
TransactionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public AService { | |
@Autowired private ARepository repository; | |
@Transactional | |
public void save(A a) { | |
repository.save(a); | |
// update(a); // update 트랜잭션 적용안됨 XXX | |
} | |
@Trnasaction(propagation = Propagation.REQURIES_NEW) | |
public void update(A a) { | |
return repository.save(a); | |
} | |
} | |
public class BService { | |
@Autowired private BRepository repository; | |
public void save(B b) { | |
repository.save(b); | |
} | |
public void update(A a) { | |
return repository.save(a); | |
} | |
} | |
public class FrontService { // 컨트롤러에서 사용하는 서비스 | |
@Autowired AService aService; | |
@Autowired BService bService; | |
@Transactional // OK | |
public void saveAB(ADto adto, BDto bdto) { | |
// dto -> A, B로 컨버팅 됐다고 가정 | |
save(b); | |
save(a); | |
} | |
public void saveOnlyA(ADto adto) { | |
// dto -> A로 컨버팅 됐다고 가정 | |
save(a); // ok | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment