[Spring] 16. annotation transaction @ Transactional. spring annotation transactions are not rolled back.

Source: Internet
Author: User

[Spring] 16. annotation transaction @ Transactional. spring annotation transactions are not rolled back.

Spring transaction Annotation

Throw new RuntimeException ("...") by default; rollback
Throw new Exception ("...") to be captured; will not be rolled back

// Specify rollback
@ Transactional (rollbackFor = Exception. class)
Public void methodName (){
// Does not roll back
Throw new Exception ("...");
}
// Do not roll back
@ Transactional (noRollbackFor = Exception. class)
Public ItimDaoImpl getItemDaoImpl (){
// Rollback
Throw new RuntimeException ("comment ");
}

// If a transaction exists, add it to the transaction. If no transaction exists, create a new one (without writing)
@ Transactional (propagation = Propagation. REQUIRED)
// The container does not start the transaction for this method
@ Transactional (propagation = Propagation. NOT_SUPPORTED)
// No matter whether a transaction exists or not, a new transaction is created, the original transaction is suspended, the new execution is completed, and the old transaction continues to be executed.
@ Transactional (propagation = Propagation. REQUIRES_NEW)
// It must be executed in an existing transaction; otherwise, an exception is thrown.
@ Transactional (propagation = Propagation. MANDATORY)
// It must be executed in a non-existing transaction; otherwise, an exception is thrown (opposite to Propagation. MANDATORY)
@ Transactional (propagation = Propagation. NEVER)
// If other beans call this method and declare transactions in other beans, use transactions. If other beans do not declare transactions, no transactions are required.
@ Transactional (propagation = Propagation. SUPPORTS)

/*
Public void methodName (){
// Method 1 of this class
Update ();
// Call the modification method of other classes
OtherBean. update ();
// Method 2 of this class
Update ();
}
If the other fails, the modification submission of this class will not be affected.
The update of this class fails, and the other fails.
*/
@ Transactional (propagation = Propagation. NESTED)
// ReadOnly = true read-only, cannot be updated, delete
@ Transactional (propagation = Propagation. REQUIRED, readOnly = true)
// Set the timeout value
@ Transactional (propagation = Propagation. REQUIRED, timeout = 30)
// Set the database isolation level
@ Transactional (propagation = Propagation. REQUIRED, isolation = Isolation. DEFAULT)

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.