Declarative or Programmatic Transaction in Spring

后端 未结 6 1544
小蘑菇
小蘑菇 2021-02-03 10:27

What type of transaction management strategy we should use in Spring? Declarative or Programmatic? Which one is better and under what situation one should use it? Can you give a

6条回答
  •  情深已故
    2021-02-03 11:25

    Programmatic transaction management is usually a good idea only if you have a small number of transactional operations. For example, if you have a web application that require transactions only for certain update operations, you may not want to set up transactional proxies using Spring or any other technology. In this case, using the TransactionTemplate may be a good approach. Being able to set the transaction name explicitly is also something that can only be done using the programmatic approach to transaction management.

    On the other hand, if your application has numerous transactional operations, declarative transaction management is usually worthwhile. It keeps transaction management out of business logic, and is not difficult to configure.

提交回复
热议问题