www.pudn.com > Desktop.rar > Hibernate3Util.java, change:2016-06-16,size:904b


package models; 
import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.Configuration; 
 
/** 
 * 供Hibernate V3版 使用 
 *  
 * @author mahc 
 *  
 */ 
public class Hibernate3Util { 
 
	private static SessionFactory sessionFactory; 
	private static Session session; 
 
	static { 
		// 创建Configuration,该对象用于读取hibernate.cfg.xml,并完成初始化 
		Configuration config = new Configuration(); 
		config.configure(); 
		sessionFactory = config.buildSessionFactory(); 
	} 
 
	/** 
	 * 获取SessionFactory 
	 *  
	 * @return 
	 */ 
	public static SessionFactory getSessionFactory() { 
		return sessionFactory; 
	} 
 
	public static Session getCurrentSession() { 
		session = sessionFactory.openSession(); 
		return session; 
	} 
 
	public static void closeSession(Session session) { 
 
		if (null != session) { 
			session.close(); 
		} 
	} 
}