HibernateUtil

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public final class HibernateUtil {
    private HibernateUtil(){}
    private static SessionFactory sessionFactory;
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    public static void setSessionFactory(SessionFactory sessionFactory) {
        HibernateUtil.sessionFactory = sessionFactory;
    }
     static{ 
         Configuration cfg = new Configuration();
         cfg.configure();
         ServiceRegistry  sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
         sessionFactory = cfg.buildSessionFactory(sr);
     
     }
     
     
     
     
}

你可能感兴趣的:(Hibernate)