@transactional handling of transaction exceptions in spring

Source: Internet
Author: User
Tags rollback

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








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.