<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
    主站蜘蛛池模板: 久久国产精品免费| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | av无码国产在线看免费网站| 久久久久亚洲爆乳少妇无| jzzijzzij在线观看亚洲熟妇| 国产成人免费爽爽爽视频| 亚洲人成毛片线播放| 18禁成人网站免费观看| 91亚洲国产成人精品下载| 69视频在线观看免费| 久久久久亚洲AV无码专区首JN| 无码精品一区二区三区免费视频| 亚洲精品无码av人在线观看| 成全在线观看免费观看大全 | 国产在线a不卡免费视频| 日本高清色本免费现在观看| 亚洲精品无码久久| 国产在线一区二区综合免费视频| 亚洲综合亚洲综合网成人| 五月天国产成人AV免费观看| 中文字幕无码精品亚洲资源网| 最新亚洲成av人免费看| 久久综合图区亚洲综合图区| 2020因为爱你带字幕免费观看全集| 亚洲色图国产精品| 国产精品久久免费| 亚洲女子高潮不断爆白浆| 免费播放春色aⅴ视频| 九九热久久免费视频| 亚洲成色999久久网站| 亚洲一区免费视频| 亚洲AV无码一区二区三区久久精品| 全黄性性激高免费视频| 中文字幕无线码中文字幕免费| 亚洲国产精品第一区二区| 大学生一级毛片免费看| 羞羞网站免费观看| 久久久久久99av无码免费网站| 亚洲国产区男人本色| 国产av无码专区亚洲av果冻传媒| 无码av免费网站|