hibernate 3.x 与 4.x 获取sessionFactory 方式

hibernate3.X

 /**
        * hibernate3.X读取配置文件并且获取session对象的方式  (对于4版本使用已经是过期)
        */
    @Test
    public void TestConfig3X(){
        Configuration config = new Configuration().configure("/config.xml");
        SessionFactory sessionFactory = config.buildSessionFactory();
        Session session =sessionFactory.openSession();
        System.out.println(session);
    }

hibernate4.X

/**
     * hibernate4.X读取配置文件并且获取session对象的方式 (现在已经有hibernate 5的最新版本)
     */
    @Test
    public void TestConfig4X(){
        Configuration config = new Configuration().configure("/config.xml");
        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
        ServiceRegistry scg = builder.applySettings(config.getProperties()).buildServiceRegistry();
        SessionFactory sessionFactory = config.buildSessionFactory(scg);
        Session session = sessionFactory.openSession();
        System.out.println(session);
    }

你可能感兴趣的:(hibernate)