此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【nightancer】截止到2008-07-08 18:37:57的历史汇总数据(不包括此帖):
发帖的总数量:0                        发帖的总分数:0                        每贴平均分数:0                        
回帖的总数量:5                        得分贴总数量:0                        回帖的得分率:0%                       
结贴的总数量:0                        结贴的总分数:0                        
无满意结贴数:0                        无满意结贴分:0                        
未结的帖子数:0                        未结的总分数:0                        
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html

解决方案 »

  1.   

    closeSessionIfNecessary根据该session是否已和transaction绑定来决定是否关闭session
      

  2.   

    类:  
          org.springframework.orm.hibernate3.SessionFactoryUtils 
    方法:
    public static void releaseSession
    (
        org.hibernate.Session session, 
        org.hibernate.SessionFactory sessionFactory
    )属性:
    session - 要关闭的hibernate 的session
    sessionFactory - 创建该session的sessionFactory对象(可为空)
      

  3.   

    closeSessionIfNecessary  这个方法在2.x中已经废弃,就不用研究啦用releaseSession方法来代替了,可以看下源代码
    /**
     * Close the given Session, created via the given factory,
     * if it is not managed externally (i.e. not bound to the thread).
     * @param session the Hibernate Session to close (may be <code>null</code>)
     * @param sessionFactory Hibernate SessionFactory that the Session was created with
     * (can be <code>null</code>)
     */
    public static void releaseSession(Session session, SessionFactory sessionFactory) {
    if (session == null) {
    return;
    }
    // Only close non-transactional Sessions.
    if (!isSessionTransactional(session, sessionFactory)) {
    closeSessionOrRegisterDeferredClose(session, sessionFactory);
    }
    }
    仅当session不再是事务中的时候释放连接