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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

用StandarServiceRegistryBuilder取代了ServiceRegistryBuilder

你可能感兴趣的:(Hibernate)