Configurationconfig =newConfiguration().configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry=newStandardServiceRegistryBuilder()
.applySettings(config.getProperties()).build();
SessionFactory sessionFactory= config.addClass(News.class).addClass(User.class)
.buildSessionFactory(serviceRegistry);
Session session=sessionFactory.openSession();
Transaction transaction=session.beginTransaction();
一定要记得调用 addClass方法指明所要操作的实体class对象