Programmatic and declarative transaction Affairs

Programmatic transaction : the so-called programmatic transaction refers achieved by encoding the transaction that is similar to JDBC programming transaction management. Management or directly using TransactionTemplate underlying PlatformTransactionManager. For programmatic transaction management, spring recommended TransactionTemplate.
 
Declarative transaction : management built on AOP. Its essence is to intercept method before and after, and then create or join a transaction before the target method begins, commit or roll back the transaction in accordance with the implementation after executing the target method. The biggest advantage is declarative transaction does not need to programmatically manage transactions, transaction management so you do not need doping code in the business logic code, just do the relevant business rules declared in the configuration file (or by @Transactional based notes the way), you can apply the rule to the transaction of business logic.
 
Declarative transaction management is clearly superior to programmatic transaction management, which is the spring non-invasive way of development advocated.
Declarative transaction management to make business code from pollution, a common POJO objects, as long as annotate can get full transaction support. And programmatic transaction compared declarative transaction where only downside is that the latter can only be applied to most fine-grained method level, you can not do as programmatic transaction that can be applied to the block level. But even if there is such a demand, there are many alternative methods, for example, can require transaction management code block is independent method and so on.

Guess you like

Origin www.cnblogs.com/coder-wf/p/12221677.html