Spring's @transactional annotations

Source: Internet
Author: User

Spring supports two ways of "programmatic transaction management" and "Declarative transaction Management ".

Declarative transactions

Declarative transaction management is built on the AOP. The essence is to intercept the method before and after it, and then create or join a transaction before the target method starts, committing or rolling back the transaction according to execution after the target method is executed.

The greatest advantage of declarative transactions is that you do not need to programmatically manage transactions, so that you do not need to doping transaction-managed code in your business logic code, just make relevant transaction rule declarations in the configuration file (or through @transactional annotations). You can apply transaction rules to the business logic.


Transactional propagation behavior

The so-called transaction propagation behavior is that if a transaction context already exists before the current transaction is started, there are several options to specify the execution behavior of a transactional method. The transactiondefinition definition includes the following constants that represent propagation behavior:

Transactiondefinition.propagation_REQUIRED: If a transaction is currently present, the transaction is joined and a new transaction is created if there is no current transaction. This is the default value.

Transactiondefinition.propagation_requires_new: Creates a new transaction and suspends the current transaction if a transaction is currently present.

Transactiondefinition.propagation_SUPPORTS: If a transaction is currently present, the transaction is joined, and if no transaction is currently present, it will continue in a non-transactional manner.

Transactiondefinition.propagation_not_supported: Runs in a non-transactional manner, suspending the current transaction if a transaction is currently present.

Transactiondefinition.propagation_never: Runs in a non-transactional manner and throws an exception if a transaction is currently present.

Transactiondefinition.propagation_MANDATORY: If a transaction is currently present, the transaction is joined and an exception is thrown if there is no current transaction.

Transactiondefinition.propagation_NESTED: If a transaction is currently present, create a transaction to run as a nested transaction for the current transaction, or if there is no current transaction, The value is equivalent to transactiondefinition.propagation_required.



Reference: Spring Transaction description

Spring's @transactional annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.