public static Session currentSession() throws HibernateException { Session s = session.get(); if (s == null) { s = sessionFactory.openSession(); session.set(s); } return s; }
public static Session currentSession() { Session s = (Session) session.get(); // Open a new Session, if this Thread has none yet if (s == null) { s = sessionFactory.openSession(); session.set(s); } return s; }
public static Session openSession() throws HibernateException { buildIfNeeded(); Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) { session = sessionFactory.openSession(); threadLocal.set(session); } return session; }
public static Session currentSession() throws HibernateException { Session s = session.get(); // 如果该线程还没有Session,则创建一个新的Session if (s == null) { s = sessionFactory.openSession(); // 将获得的Session变量存储在ThreadLocal变量session里 session.set(s); } return s; }
public static void close(Session session) { session = (Session) threadLocal.get(); threadLocal.set(null); if (session != null) { try { session.close(); } catch (HibernateException e) { System.out.println(e); } } }
public static void closeSession() throws HibernateException { Session s = session.get(); if (s != null) s.close(); session.set(null); }
public static void closeSession() { Session s = (Session) session.get(); if (s != null) s.close(); session.set(null); }