@Override
@Transactional(transactionManager="db1PlatformTransactionManager", propagation= Propagation.REQUIRED_NEW, rollbackFor = {InsufficientFundsException.class, EntityNotFoundException.class}, isolation=Isolation.READ_COMMITTED)
public Account creditAmount(AccountDto accountDto, BigDecimal creditAmt) throws EntityNotFoundException{
throw new EntityNotFoundException(Account.class, "accountNumber", accountDto.getAccountNumber().toString());
}
@Override
@Transactional(transactionManager="db1PlatformTransactionManager", propagation= Propagation.REQUIRED_NEW, rollbackFor = {InsufficientFundsException.class, EntityNotFoundException.class}, isolation=Isolation.READ_COMMITTED)
public Account debitAmount(AccountDto accountDto, BigDecimal debitAmt) throws EntityNotFoundException, InsufficientFundsException {
assert(debitAmt.compareTo(BigDecimal.ZERO) == 1); //assert greater than 0
Optional<Account> accountInDb = accountRepository.findById(accountDto.getAccountNumber());
if (accountInDb.isPresent()) {
Account account = accountInDb.get();
account.debit(debitAmt);
return accountRepository.save(account);
}
throw new EntityNotFoundException(Account.class, "accountNumber", accountDto.getAccountNumber().toString());
}
@Override
@Transactional(transactionManager="db1PlatformTransactionManager", propagation=Propagation.REQUIRED, rollbackFor = {InsufficientFundsException.class, EntityNotFoundException.class}, isolation=Isolation.READ_COMMITTED)
public List<Account> transferFunds(AccountDto debitAccountDto, AccountDto creditAccountDto, BigDecimal amount) throws EntityNotFoundException, InsufficientFundsException {
assert(amount.compareTo(BigDecimal.ZERO) == 1); //assert greater than 0
Account debitAccount = debitAmount(debitAccountDto, amount);
Account creditAccount = creditAmount(creditAccountDto, amount); // throws exception
return Stream
.of(debitAccount, creditAccount)
.collect(Collectors.toList());
}
, как вы видите, метод creditAmount выдает исключение, а метод debitAmount имеет PRAPOGATION как REQUIRED_NEW. исключено, так как debitAmount должен фиксировать данные, но также получает откат