thombergs / buckpal

An example approach for implementing a Clean/Hexagonal Architecture
https://leanpub.com/get-your-hands-dirty-on-clean-architecture/overview
2.18k stars 666 forks source link

About Transactions #24

Open chiaradiamarcelo opened 3 years ago

chiaradiamarcelo commented 3 years ago

Hi @thombergs,

I was taking a look at the implementation of the SendMoneyService (https://github.com/thombergs/buckpal/blob/master/src/main/java/io/reflectoring/buckpal/account/application/service/SendMoneyService.java).

It seems you are implementing pessimistic locking by explicitly locking the banck accounts with the AccountLock.

I can see that you also handle the transaction (either commit/rollback) with javax's Transactional.

Given that the locks on the bank accounts are released before the transaction is committed/rollback, how can you make sure that in between (ie, when the locks are released but before the commit/rollback is done) there's not another transaction executed with the same bank accounts before this one is fully finished?

Thanks