Java Manual things ROLLBACK TRANSACTION

Source: Internet
Author: User

1. Spring MVC Configuration Exception thing rollback mechanism

<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" init-method= "Init" destroy-method= "Close" >
...... Omitted
</bean>

<!--transaction Manager--
<bean id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource"/>
</bean>

<!--transaction Control--
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "save*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "do*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "insert*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "add*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "update*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "edit*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "remove*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "delete*" propagation= "REQUIRED" rollback-for= "Exception"/>
<tx:method name= "get*" read-only= "true"/>
<tx:method name= "select*" read-only= "true"/>
<tx:method name= "find*" read-only= "true"/>
</tx:attributes>
</tx:advice>

2, in special cases, the use of manual things rollback, as follows

Note: Manual thing rollback is simple, but does not conform to spring's non-intrusive nature and makes the code highly coupled with the things of the spring framework.

Transactionaspectsupport.currenttransactionstatus (). Setrollbackonly ();

Java Manual things ROLLBACK TRANSACTION

Related Article

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.