All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.phoenix.basic.utils.HibernateUtil Maven / Gradle / Ivy

Go to download

对hibernate4的封装。封装了Druid,通过Druid可以轻量级的对其他数据库进行操作

The newest version!
package org.phoenix.basic.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
/**
 * hibernate工具类
 * @author mengfeiyang
 *
 */
public class HibernateUtil {
	private final static SessionFactory FACTORY = buildSessionFactory();
    //new File("c:\\phoenix\\hibernate.cfg.xml")
	private static SessionFactory buildSessionFactory() {
		Configuration cfg = new Configuration().configure();
		ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
		SessionFactory factory = cfg.buildSessionFactory(serviceRegistry);
		return factory;
	}
	
	public static SessionFactory getSessionFactory() {
		return FACTORY;
	}
	
	public static  Session openSession() {
		return FACTORY.openSession();
	}
	
	public static void closeSession(Session session) {
		if(session!=null)session.close();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy