HibernateUtil
hibernate工具类:
package cn.bdqn.hibernate_Criteria.Util; import org.hibernate.Session; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static Session session; private static ThreadLocal<Session> sl=new ThreadLocal<Session>(); public static Session getSession(){ session=sl.get(); if(session==null){ session=new Configuration().configure().buildSessionFactory().openSession(); sl.set(session); } return session; } public static void closeSession(){ session=sl.get(); sl.set(null); session.close(); } }