<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 閱讀(9743) 評論(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 | 枷鎖
    贊……………………  回復  更多評論
      

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


    網站導航:
     
    <2009年9月>
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲区小说区图片区| 大学生高清一级毛片免费| AV在线亚洲男人的天堂| 99亚洲男女激情在线观看| 日本不卡在线观看免费v| 亚洲精品欧美综合四区| 国产最新凸凹视频免费| 免费观看亚洲人成网站| 亚洲综合色成在线播放| 国产黄在线观看免费观看不卡| 久久99亚洲综合精品首页 | 国产成人一区二区三区视频免费| 国产亚洲无线码一区二区| 性xxxx视频免费播放直播| 久久亚洲精精品中文字幕| 91九色老熟女免费资源站| 一级毛片正片免费视频手机看| 免费网站看v片在线香蕉| 国产区图片区小说区亚洲区| 亚洲成人国产精品| 免费无码又爽又刺激网站| 亚洲国产综合专区电影在线| 成人浮力影院免费看| 亚洲Aⅴ在线无码播放毛片一线天| 国产亚洲福利一区二区免费看| 人妻仑乱A级毛片免费看| 亚洲国产精品成人精品无码区在线| 在线看无码的免费网站| 久久亚洲国产精品123区| 久久这里只精品99re免费 | tom影院亚洲国产一区二区| 永久免费观看的毛片的网站| 免费一级毛suv好看的国产网站| 国产亚洲综合网曝门系列| 无码av免费毛片一区二区| 久久精品国产亚洲AV网站| 国产在线精品一区免费香蕉| 亚洲另类小说图片| 色久悠悠婷婷综合在线亚洲| 国产成人精品久久免费动漫| 污视频网站在线观看免费|