Hibernate 最简单例子 (3)

     *ReturnstheThreadLocalSessioninstance.  Lazyinitialize

     *the<code>SessionFactory</code>ifneeded.

     *

     *  @returnSession

     *  @throwsHibernateException

     */

    publicstatic Session getSession() throws HibernateException {

        Session session = (Session) threadLocal.get();

 

       if (session == null || !session.isOpen()) {

           if (sessionFactory == null) {

              rebuildSessionFactory();

           }

           session = (sessionFactory != null) ? sessionFactory.openSession()

                  : null;

           threadLocal.set(session);

       }

 

        return session;

    }

 

    /**

     *  Rebuildhibernatesessionfactory

     *

     */

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjzyw.html