Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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);
     }
   }
 }
Ejemplo n.º 6
0
 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);
  }