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可以轻量级的对其他数据库进行操作

There is a newer version: 1.5.1
Show 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;

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