Try catch transaction does not roll

Source: Internet
Author: User
Tags try catch

In the spring mechanism, after a transaction is configured, if a try catch catches an exception, because the exception is already caught, the transaction does not roll, resulting in a lot of dirty data.
Workaround:
1. Throws an exception in the catch (throw new RuntimeException (")") and is run-time exception, throwing a normal exception will not roll.
2. If the annotation is configured, then the method of the Try (method) catch can be presented separately as a method, then add the annotation @transactional on this method, then this approach will be rolled,
and exceptions can be captured normally.
Use Try catch reasonably. When refactoring the code, many unreasonable uses are found, resulting in a lot of dirty data, which leads to occasional user protection, but the problem cannot be located.

Try catch transaction does not roll

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.