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