hibernate4 获取SessionFactory

//读取hibernate.cfg.xml文件  
        Configuration cfg = new Configuration().configure(); 
//      建立SessionFactory 
        //buildSessionFactory 过时
//      SessionFactory factory = cfg.buildSessionFactory();   
        //ServiceRegistryBuilder 过时
//      ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
//      SessionFactory factory = cfg.buildSessionFactory(serviceRegistry);
        //4.X 
        StandardServiceRegistry standardServiceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
        SessionFactory factory = cfg.buildSessionFactory(standardServiceRegistry);


你可能感兴趣的:(Hibernate)