There are serveal problems here:
- There is not point in wrapping a direct update like that in a database transaction. It only makes sense to use a db transaction when you have more than one action (or when you want to lock the object).
- After you update the balance, how do you know what is the new balance? If the initial balance was 100$ and you deposited 50$, is it safe to assume the new balance is 150$? No it’s not. Another session might updated the balance in the meantime so either way you have to fetch the object again to check the current balance. If you dont need to know the new balance then there is not problem, other wise you didn’t save any queries.