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

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

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

    在spring+hibernate的時候,控制臺提示“unclosed connection,forgot to call close() on your session?”
    或者是[org.hibernate.jdbc.ConnectionManager] - <finalizing with closed connection>
    那是因為有可能是你自己手動創(chuàng)建了session,比如:

    private static final SessionFactory sessionFactory;

        static {
            try {
                // Create the SessionFactory from hibernate.cfg.xml
                sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
    然后調(diào)用:

    Session session = sessionFactory.openSession();
    Query query = session.createQuery("from Login");

    類似這樣的單獨使用hibernate時的用法,是需要手工去關(guān)閉session的。沒有關(guān)閉的話就會收到那樣的警告。

    所以最好是使用spring管理的session,和OpenSessionInViewFilter,比如:
    Session session =this.getSession();
    然后在web.xml里加入
      <filter>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
      </filter>
      <filter-mapping>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    其中在spring里注冊的sessionfactory必須是id="sessionFactory",如果是id="SessionFactory"或者其他,會提示sessionFactory沒有注冊的錯誤,因為OpenSessionInViewFilter里注冊的名必須為sessionFactory。

    posted on 2008-01-10 18:41 lzj520 閱讀(4838) 評論(5)  編輯  收藏 所屬分類: Spring個人學(xué)習(xí)日記Hibernate
    主站蜘蛛池模板: 狠狠色伊人亚洲综合成人| 久久受www免费人成_看片中文| 久久精品国产亚洲| AAAAA级少妇高潮大片免费看| 久久国产精品国产自线拍免费| 免费在线观看视频网站| 亚洲美免无码中文字幕在线| 久久亚洲精品国产精品婷婷| 999国内精品永久免费观看| 亚洲国产高清美女在线观看| 男人和女人高潮免费网站 | 麻豆国产精品免费视频| 亚洲校园春色小说| 18禁成年无码免费网站无遮挡| 亚洲精品二三区伊人久久| 一级毛片a免费播放王色电影| 最近中文字幕大全中文字幕免费| 伊人久久综在合线亚洲2019| 又粗又大又黑又长的免费视频| 亚洲中文字幕乱码一区| 久久99精品免费一区二区| 亚洲AV综合色区无码一区| 人与禽交免费网站视频| 亚洲人成电影网站久久| 免费一级大黄特色大片| 国产午夜精品理论片免费观看 | 久久国产福利免费| 亚洲AV无码一区东京热| 在线视频精品免费| 国产亚洲综合一区二区三区| 日韩中文字幕精品免费一区| 亚洲av无码一区二区三区在线播放 | 四虎影永久在线高清免费| 亚洲精品第五页中文字幕| 日本人的色道www免费一区| 久久av免费天堂小草播放| 亚洲国产精品日韩在线| 亚洲不卡无码av中文字幕| 亚洲av无码专区青青草原| 无码久久精品国产亚洲Av影片| 免费电视剧在线观看|