cybersecuritybase / cybersecuritybase.github.io

Cyber Security Base with F-Secure
52 stars 26 forks source link

Part2-Database transactions #24

Closed subratrout closed 7 years ago

subratrout commented 7 years ago

If the method would not have been annotated with the @Transactional annotation, the accounts would have to be separately saved if we want to commit the changes to the database.

I practically see no difference between both codes. What I am missing here?

nygrenh commented 7 years ago

They're the same snippets. Definitely a mistake in the material.

Hlynrkjaer commented 6 years ago

Hello,

With CSB-2017 : Part-Two still with such snippet

@Transactional public void bankTransfer(Long fromAccount, Long toAccount, Integer amount) { Account from = accountRepository.findOne(fromAccount); Account to = accountRepository.findOne(toAccount); from.setBalance(from.getBalance() - amount); to.setBalance(to.getBalance() + amount); }

with both places (where is expected and where is not).

Does it should be with changes in the material about second situation (where is not expected):

If the method would not have been annotated with the @Transactional annotation, the accounts would have to be separately saved if we want to commit the changes to the database.

?! with drop annotation and with addition something like: accountRepository.save(from); accountRepository.save(to);

Thanks! @nygrenh