public class BusinessService { //spring bean
public dumpAllData(List){
/* Complicated DB operation here
* We dont want to be in transaction now (because of performance issues)
*/
for(...){ //iterating through whole list
**updateItem(item);**
}
}
public updateItem(Entity e){
//saves entity into DB
//we want to be in transaction now
}
}
Spring配置:彈簧+休眠,嵌套NOT_SUPPORTED事務屬性
<tx:advice id="txAdvice" transaction-manager="wsTransactionManager">
<tx:attributes>
<tx:method name="dumpAllData" propagation="NOT_SUPPORTED" />
<tx:method name="updateItem" propagation="REQUIRES_NEW" />
</tx:attributes>
</tx:advice>
可以具有嵌套REQUIRED_NEW傳播將從方法與傳播被調用NOT_SUPPORTED?
事情是我們在dumpAllData()中運行一個廣泛的數據庫操作(〜100Mb),所以我們不想在事務中(oterwise這將是性能問題)。但是我們想要在updateItem方法中進行事務(回滾/提交)(我們只是簡單地更新實體)。
在單個事務中完成的大規模數據庫更新可能會給數據庫帶來沉重的負擔(在oracle的情況下會有巨大的重做日誌)。最好在自動提交模式下執行它們,或者分成更小的塊。 – mrembisz 2012-01-09 14:44:05
Autocommit?與休眠?真的不好主意,恕我直言。見http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#batch – 2012-01-09 14:52:44
@Mrembisz:「分成小塊」 - 是的,這是我們的想法。我們希望一個接一個地做出小小的改變。你有任何有用的例子/鏈接? Thx – 2012-01-09 15:02:53