[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)