<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 64,  comments - 9,  trackbacks - 0

    org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
    最近在寫操作CLOB的過程中總是報這個異常,數據去插入進去了.


    先看看SessionFactory.getCurrentSession與openSession的區別
    1. 如果使用的是getCurrentSession來創建session的話,在commit后,session就自動被關閉了,
        也就是不用再session.close()了。但是如果使用的是openSession方法創建的session的話,
        那么必須顯示的關閉session,也就是調用session.close()方法。這樣commit后,session并沒有關閉
    /*2. getCurrentSession的使用可以參見hibernate\hibernate-3.2\doc\tutorial\src項目
    3. 使用SessionFactory.getCurrentSession()需要在hibernate.cfg.xml中如下配置:
       * 如果采用jdbc獨立引用程序配置如下:
        <property name="hibernate.current_session_context_class">thread</property>
       * 如果采用了JTA事務配置如下
        <property name="hibernate.current_session_context_class">jta</property>*/

    開始用的:

    Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
    Transaction tran=session.beginTransaction();

    好多文章里都說只需在Spring配置<bean id="sessionFactory"...---><property name="hibernateProperties">   中加入 <prop key="hibernate.current_session_context_class">thread</prop>就可以解決,試了沒用.

    修改后的:

    Session session = this.getHibernateTemplate().getSessionFactory().openSession();

    Transaction tran=session.beginTransaction();

    ......

    finally
       {  
        session.close();  
       }

    問題解決

    posted on 2009-09-11 17:06 super_nini 閱讀(9754) 評論(6)  編輯  收藏

    FeedBack:
    # re: 轉:Could not commit Hibernate 問題,spring 事物 提交前session關閉問題
    2009-10-28 14:22 | 楚門
    真是太感謝了……
    弄了半天,感覺不盡……  回復  更多評論
      
    # re: 轉:Could not commit Hibernate 問題,spring 事物 提交前session關閉問題
    2010-03-02 17:52 | 王成飛
    好文章,就是沒有理由的頂
    感激不盡....  回復  更多評論
      
    # re: 轉:Could not commit Hibernate 問題,spring 事物 提交前session關閉問題
    2010-03-15 14:46 | jspxcgy007
    好貼必須頂!  回復  更多評論
      
    # re: 轉:Could not commit Hibernate 問題,spring 事物 提交前session關閉問題
    2010-11-09 11:32 | chenj
    頂,樓主真是強啊  回復  更多評論
      
    # re: 轉:Could not commit Hibernate 問題,spring 事物 提交前session關閉問題[未登錄]
    2011-12-02 01:18 | liu
    是對的,解決了 強  回復  更多評論
      
    # re: 轉:Could not commit Hibernate 問題,spring 事物 提交前session關閉問題
    2013-01-24 15:41 | 枷鎖
    贊……………………  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2011年12月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 波多野结衣中文字幕免费视频 | 日本久久久久亚洲中字幕| 美女视频黄视大全视频免费的| 青苹果乐园免费高清在线| 亚洲欧洲日产v特级毛片| 88xx成人永久免费观看| 亚洲日本乱码一区二区在线二产线| 日韩免费高清大片在线| 亚洲人成在线电影| 亚洲免费观看网站| 国产亚洲sss在线播放| 最新仑乱免费视频| 精品韩国亚洲av无码不卡区| 日韩在线天堂免费观看| 看免费毛片天天看| 久久精品国产精品亚洲| 久久免费精彩视频| 亚洲成a人片在线观看中文app | 一级特黄特色的免费大片视频| 亚洲 另类 无码 在线| 国产乱妇高清无乱码免费| 国产亚洲色婷婷久久99精品| 久久久久国色av免费看| 亚洲最大成人网色香蕉| 午夜私人影院免费体验区| 五月婷婷免费视频| 亚洲AV乱码久久精品蜜桃| 国产精品69白浆在线观看免费 | 亚洲第一视频网站| 91情侣在线精品国产免费| 毛片亚洲AV无码精品国产午夜 | 亚洲AV无码一区二区三区系列| 97在线视频免费| 日韩国产精品亚洲а∨天堂免| 亚洲精品视频在线看| 毛片无码免费无码播放| 亚洲小说图区综合在线| 国产亚洲精品国看不卡| 午夜国产精品免费观看| 美女隐私免费视频看| 亚洲最新在线视频|