好記性不如爛筆頭92-spring3學習(13)-spring和hibernate訪問資料庫的小差異,92-spring3-spring

來源:互聯網
上載者:User

好記性不如爛筆頭92-spring3學習(13)-spring和hibernate訪問資料庫的小差異,92-spring3-spring

在Spring的資料來源(dataSource),在預設的情況下,autoCommint被設定為true。也就是說,在預設情況下,通過jdbcTemplate執行的語句馬上提交,沒有事務控制。
如果將autoCommint設定為false。那麼必須顯示提交SQL,才能正式提交。
有的資料庫為了強調速度,本身就不支援事務,比如用MyIsam引擎的mysql資料庫。這種資料庫連事務都沒有必要配置,因為它本身就沒有事務。

對於hibernate來說,當我們調用session的save,update等方法的時候,hibernate並不直接往資料庫發送SQL語句,只有在提交事務(commit)或者flush一級緩衝的時候,才真正向資料庫發送SQL並且執行。

簡單的說,spring預設是往資料庫提交SQL,而hibernate預設是不往資料庫提交SQL。

相關文章

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.