Hibernate5.1 SessionFactory获取方法

在Hibernate5.1中对sessionFactory获取的方法进行了改变

StandardServiceRegistry  serviceRegistry=new StandardServiceRegistryBuilder().configure().build(); 
        SessionFactory sessionFactory=new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
        Session session=sessionFactory.getCurrentSession();
        Transaction tx =session.beginTransaction();
        Students s=new Students("张三","男");
        session.save(s);
        tx.commit();
        tx=null;
        StandardServiceRegistryBuilder.destroy(serviceRegistry);

用StandarServiceRegistryBuilder取代了ServiceRegistryBuilder

你可能感兴趣的:(Hibernate)