Spring's Annotated transaction @Transactional

Source: Internet
Author: User

Spring Transaction annotations

default encounters throw new RuntimeException ("..."); Roll back
the throw new Exception ("...") that needs to be captured is not rolled back

//Specify rollback
@Transactional (Rollbackfor=exception.class)
public void MethodName () {
//Does not roll back
throw new Exception ("...");
}
//Specify not to roll back
@Transactional (Norollbackfor=exception.class)
Public Itimdaoimpl Getitemdaoimpl () {
//Will roll back
throw new RuntimeException ("note");
}

//If there is a transaction, then join the transaction, and then create a new one (without writing the case)
@Transactional (propagation=propagation.required)
//container does not open transactions for this method
@Transactional (propagation=propagation.not_supported)
//Regardless of whether a transaction exists, a new transaction is created, the original hangs, the new execution completes, and the old transaction continues
@Transactional (propagation=propagation.requires_new)
//must be executed in an existing transaction, or throw an exception
@Transactional (Propagation=propagation.mandatory)
//must be executed in a non-transacted transaction, otherwise throws an exception (as opposed to propagation.mandatory)
@Transactional (Propagation=propagation.never)
//If other beans call this method and declare a transaction in another bean, then use the transaction. If no other bean declares a transaction, then no transaction is necessary.
@Transactional (Propagation=propagation.supports)

    /*
Public void MethodName () {
//Modify method of this class 1
update ();
//Call modification methods of other classes
otherbean.update ();
//Modify method of this class 2
update ();
    }
Other failure does not affect the success of this class of modification submission
failure of this type of update, and other failures
    */
@Transactional (propagation=propagation.nested)
//Readonly=true Read only, cannot update, delete
@Transactional (propagation = propagation.required,readonly=true)
//Set timeout time
@Transactional (propagation = propagation.required,timeout=30)
//Set database Isolation Level
@Transactional (propagation = Propagation.required,isolation=isolation.default)


For example, if the old data fails to delete, the new data is not created



Spring's Annotated transaction @Transactional

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.