使用hibernatetemplate時,不顯示的宣告事務管理,照樣能對資料庫做curd。
這是因為在沒有宣告事務時,hibernatetemplate是預設自動提交事務的。
因此如果在業務**中,只涉及到一次資料庫操作時預設自動事務提交已經足夠,如果多次資料庫操作則需要做事務宣告。
hibernatetemplate有點類似事務中的propagation
的required. 當你在spring配置了事務的時候,hibernatetemplate就會用當前spring
配置的事務,如果spring沒有配置事務,然而hibernatetemplate又是必須要乙個事務,
則它會自己建立乙個事務開始並提交!!
HibernateTemplate相關方法
向資料庫新增一條對應於乙個業務物件例項的記錄 param entity 業務物件例項 public entity create entity entity throws daoexception catch dataacces ception e 向資料庫更新一條對應於乙個業務物件例項的記錄 par...
HibernateTemplate中執行sql語句
hibernatetemplate中執行sql語句 杯具,居然有個很明顯的錯誤 getsession 應改為 session 使用匿名內部類的入參session,否則spring不進行session的生命週期管理。建立可更新 update 和刪除 delete 的sql suppresswarnin...
HibernateTemplate相關方法
向資料庫新增一條對應於乙個業務物件例項的記錄 param entity 業務物件例項 publicentity create entity entity throwsdaoexceptioncatch dataacces ception e 向資料庫更新一條對應於乙個業務物件例項的記錄 param ...