<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 | 枷鎖
    贊……………………  回復  更多評論
      

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


    網站導航:
     
    <2010年11月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 毛片免费在线播放| 91免费国产在线观看| 免费在线观看理论片| 亚洲欧洲国产综合AV无码久久| 永久看日本大片免费35分钟| 久久亚洲精品无码VA大香大香| 免费精品一区二区三区第35| 亚洲日韩中文无码久久| 久久99免费视频| 亚洲丝袜美腿视频| 57pao国产成永久免费视频| 亚洲综合图片小说区热久久| 91精品国产免费久久久久久青草| 亚洲偷自精品三十六区| 在线jyzzjyzz免费视频| 91老湿机福利免费体验| 亚洲最大黄色网址| A级毛片内射免费视频| 亚洲精品无码久久久久APP| 永久黄网站色视频免费| 成人免费夜片在线观看| 亚洲午夜无码久久久久| 久久国产免费观看精品3| 亚洲偷自精品三十六区| 亚洲精品无码久久久久AV麻豆| 在线免费观看伊人三级电影| 久久亚洲精精品中文字幕| 午夜福利不卡片在线播放免费| 亚洲乱人伦中文字幕无码| 亚洲国产精品专区在线观看| 最近中文字幕大全免费版在线 | 24小时在线免费视频| 亚洲熟妇无码AV| 亚洲乱码无码永久不卡在线| 亚洲免费网站在线观看| 大桥未久亚洲无av码在线| 亚洲爆乳无码一区二区三区| 成**人免费一级毛片| 国产亚洲精品免费视频播放| 亚洲偷自精品三十六区| 亚洲日韩精品A∨片无码|