Spring transaction control and rollback

Source: Internet
Author: User

1 in a project SSH structure, spring2.5, transaction control using the method of the TX interceptor.

I wrote an int a=1/0, the exception is thrown, but the transaction is submitted, how can not do.

Some of the transaction controls that you will see now are summarized:

The transaction control rolls back the RuntimeException (array out of bounds, the result is 0, and so on) and is a notchecked exception.

Note: Exceptions within SQL are not rolled back by default

If there is a try in the service: Catch form, the exception cannot be thrown and is not rolled back. It is therefore necessary to throw the new runtimeexception in the catch to add the active throw on the method.

In the TX section be aware that you can set <tx:method roback-for= ' Exception ' to capture the exceptions you specify. @transactional (Robackfor=exception.class) If declarative annotations are used

If this does not work, you can only use the following manual throw in the catch of the service.

Transactionaspectsupport.currenttransactionstatus (). Setrollbackonly ();

Reference article:

(Spring transaction Transaction Roll back various rollback) https://www.cnblogs.com/wangchuanfu/p/8110159.html

(The spring transaction uses the TX tag to configure the Interceptor) http://blog.sina.com.cn/s/blog_486c3b620100xuh7.html

(5 ways to configure Spring2.5 transactions) https://www.cnblogs.com/gaoyoubo/articles/1861464.html

(Spring transaction attribute analysis) https://www.cnblogs.com/aliger/p/3898869.html

(Spring declarative transaction does not roll back the problem) http://www.jianshu.com/p/f5fc14bde8a0

(Spring transaction does not roll back) https://www.cnblogs.com/lidelin/p/7266280.html

Spring transaction control and rollback

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.