By default, the hibernate records a sequence of commands (wrappers over requests), and then, at the request of a commit. One of the reasons for this approach is the ability to roll back changes if an error occurred. Why else?
1 answer
Transactions are needed not only in order to have the possibility of rollback, but also so that the intermediate result does not interfere with the logic of work.
Say, customer A’s account is debited and transferred to another customer’s account B, the transaction takes place in 2 steps: first, you deduct the account from A’s account, then add the same money to B.’s account balance. the sum of accounts A + B at the time of the debit from account A will cause a logical error, since the amount of the operation will hang in the air. In fact, this will mean a loss of integrity. Or in ACID terms, consistency .
- and if translated into the query language, can it happen that N> 2 queries from different sources to the database can break the integrity and get incorrect results? - voipp
- Yes, if there is no transaction, then that's exactly what will happen. - Barmaley
|