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