0
我在同一課程中,對三個不同的表格一個接一個地執行三次crud操作。如果發生任何異常。我怎麼能在spring + hibernate之前回滾之前執行的其他crud。多次在春季回滾+如果發生異常,則全部休眠任何
我在同一課程中,對三個不同的表格一個接一個地執行三次crud操作。如果發生任何異常。我怎麼能在spring + hibernate之前回滾之前執行的其他crud。多次在春季回滾+如果發生異常,則全部休眠任何
在您的方法上使用@Transactional註釋並指定事務管理器。
從春天文檔: http://docs.spring.io/autorepo/docs/spring/4.2.x/spring-framework-reference/html/transaction.html
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
並在代碼:
@Transactional
public void updateThreeTables() {
// Update
// Update
// This error will rollback all three
}