使用hibernate中connection.release_mode,connection.autocommit和transaction.auto_close_session用法及需要注意的問題
Posted on 2011-08-04 15:57 瘋狂 閱讀(13225) 評(píng)論(0) 編輯 收藏 所屬分類: hibernate 、方法論hibernate默認(rèn)情況:
<property name="connection.release_mode">auto</property>--釋放jdbc resources 方式 如果不配置默認(rèn)是auto (當(dāng)然現(xiàn)在沒有auto了,等同于"after_statement" or "after_transaction"),注意3.0以及之前默認(rèn)是ON_CLOSE(也就是session關(guān)閉才釋放jdbc鏈接)
<property name="transaction.auto_close_session">false</property>--自動(dòng)關(guān)閉session
<property name="connection.autocommit">false</property>--自動(dòng)提交
release_mode的設(shè)置見于:http://www.aygfsteel.com/freeman1984/archive/2011/07/27/355110.html
1 首先connection.autocommit配置成false的情況:
此種情況需要手動(dòng)開啟事務(wù),需要手動(dòng)開啟transaction,以及提交transaction,并且此時(shí)transaction.auto_close_session配置的配置將自動(dòng)設(shè)置為false,所以此時(shí)如果connection.release_mode配置為on_close()時(shí)需要手動(dòng)關(guān)閉session才能釋放JDBC 連接,日志會(huì)提示:
transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
因此connection.autocommit為false的情況建議connection.release_mode采取默認(rèn)auto。
2 connection.autocommit為true的情況,此時(shí)不需要手動(dòng)開啟transaction以及提交transaction,hibernate自動(dòng)開始transaction并在每次操作后提交transaction,設(shè)置此 時(shí)transaction.auto_close_session設(shè)置將自動(dòng)為false。 如果connection.release_mode配置為on_close()是需要手動(dòng)關(guān)閉session才能釋放JDBC 連接.建議此種情況connection.release_mode設(shè)置默認(rèn)auto。
3 connection.autocommit為true的情況,如果此時(shí)又手動(dòng)開啟了transaction,此時(shí)connection.autocommit將被設(shè)置為false(disabling autocommit),需要手動(dòng)提交transaction,此種情況如同第一種情況。
有問題請(qǐng)補(bǔ)充。tks
<property name="connection.release_mode">auto</property>--釋放jdbc resources 方式 如果不配置默認(rèn)是auto (當(dāng)然現(xiàn)在沒有auto了,等同于"after_statement" or "after_transaction"),注意3.0以及之前默認(rèn)是ON_CLOSE(也就是session關(guān)閉才釋放jdbc鏈接)
<property name="transaction.auto_close_session">false</property>--自動(dòng)關(guān)閉session
<property name="connection.autocommit">false</property>--自動(dòng)提交
release_mode的設(shè)置見于:http://www.aygfsteel.com/freeman1984/archive/2011/07/27/355110.html
1 首先connection.autocommit配置成false的情況:
此種情況需要手動(dòng)開啟事務(wù),需要手動(dòng)開啟transaction,以及提交transaction,并且此時(shí)transaction.auto_close_session配置的配置將自動(dòng)設(shè)置為false,所以此時(shí)如果connection.release_mode配置為on_close()時(shí)需要手動(dòng)關(guān)閉session才能釋放JDBC 連接,日志會(huì)提示:
transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
因此connection.autocommit為false的情況建議connection.release_mode采取默認(rèn)auto。
2 connection.autocommit為true的情況,此時(shí)不需要手動(dòng)開啟transaction以及提交transaction,hibernate自動(dòng)開始transaction并在每次操作后提交transaction,設(shè)置此 時(shí)transaction.auto_close_session設(shè)置將自動(dòng)為false。 如果connection.release_mode配置為on_close()是需要手動(dòng)關(guān)閉session才能釋放JDBC 連接.建議此種情況connection.release_mode設(shè)置默認(rèn)auto。
3 connection.autocommit為true的情況,如果此時(shí)又手動(dòng)開啟了transaction,此時(shí)connection.autocommit將被設(shè)置為false(disabling autocommit),需要手動(dòng)提交transaction,此種情況如同第一種情況。
有問題請(qǐng)補(bǔ)充。tks