Good day! Should I start a transaction when searching for an entity in the database (get (...), load (...))? In essence, the transaction will not make sense here. So?

  • It depends on whether one or several clients work with the database. - smackmychi

1 answer 1

If a database request is in fact only SQL select , then wrapping the request with transactions is meaningless, with one small clarification:

If you are not trying to change the transaction isolation level before the request. By default, transaction isolation level is usually set to READ_COMITTED , that is, records that have already passed the commit will be visible.

In some cases, to speed up requests, you can try to set the transaction isolation level to READ_UNCOMITTED (read pending transactions) or, on the contrary, tighten the isolation requirement by setting READ_SERIALIZABLE (read only saved transactions).

So in this case, you need to wrap the select with transactions. In all other cases, it does not make sense.