Spring's handling of transaction exceptions
Unchecked run exception spring defaults to transaction rollback for example: runtimeexception
//checked User Exception Spring does not perform transaction rollback by default such as: Exception
How to change this default transaction behavior for spring. You can use the method
add @transactional (norollbackfor=runtimeexception.class) Let spring do not rollback transaction for RuntimeException
add @transactional (rollbackfor=exception.class) allow spring to rollback transactions for Exception
@Transactional (propagation=propagation.required)
required as default behavior
If an exception to an internal Try/catch block only causes a rollback of the internal Try/catch block transaction, the internal Try/catch block operation is not performed, but the other operation is still performed.
if an external exception results in a rollback of the entire transaction, all operations are not performed, even if the internal Try/catch block does not appear to be abnormal.
@Transactional (readonly=true)
read-only property, do not allow update operation, can improve efficiency
@Transactional (timeout=30)
Timeout, defaults to 30 seconds
@Transactional (Isolation=isolation.repeatable_read)
Transaction ISOLATION Level
MySQL defaults to the third level of Repeatable_read
MSSQLSERVER2000 defaults to the second level read_committed
MSSQLSERVER2005 can be set to a 23rd level and not less efficient than the second level
The higher the level, the lower the efficiency