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

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


    網站導航:
     
    <2013年1月>
    303112345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲欧美成aⅴ人在线观看| 丰满少妇作爱视频免费观看| 亚洲人妖女同在线播放| 久久亚洲AV成人无码国产最大| 中文字幕免费在线视频| 国产免费看JIZZ视频| 久久国产成人精品国产成人亚洲| 亚洲婷婷综合色高清在线| 春意影院午夜爽爽爽免费| 97热久久免费频精品99| 中文字幕在亚洲第一在线| av电影在线免费看| 成人毛片免费播放| 亚洲电影一区二区| 深夜A级毛片视频免费| 三年片在线观看免费大全| 亚洲伦理中文字幕| 99精品在线免费观看| 久久亚洲国产成人影院网站 | 中文字幕久久亚洲一区| 亚洲色成人网站WWW永久四虎| 久久大香伊焦在人线免费| 波多野结衣中文一区二区免费 | 国产美女精品视频免费观看| 亚洲高清免费在线观看| a级毛片在线视频免费观看| 免费人成年激情视频在线观看| 日韩毛片免费一二三| 亚洲午夜久久久久妓女影院| 国产成人无码免费网站| 久久久久亚洲精品天堂| 毛片在线播放免费观看| 久久久久国产成人精品亚洲午夜 | 亚欧色视频在线观看免费| 亚洲精品无码专区久久久 | baoyu122.永久免费视频| 亚洲国产美女在线观看| 四虎免费影院4hu永久免费| 亚洲狠狠婷婷综合久久蜜芽| 永久免费av无码不卡在线观看| 亚洲a无码综合a国产av中文|