hibernate 5.2.12配置

//创建服务注册对象

       ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
       //创建会话工厂对象
       SessionFactory sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
       //会话对象
       Session session = sessionFactory.openSession();
       //开启事物
       Transaction transaction = session.beginTransaction();
       //输入实体类的信息
       System.out.println("请依次输入:账号  密码");
       int name=cin.nextInt();
       String pwd=cin.next();
       Admin admin=new Admin(name,pwd);
       System.out.println(name+" :"+pwd);
       //保存到数据库,持久化操作
       session.save(admin);
       //提交事务
       transaction.commit();
       //关闭会话
       session.close();
       //关闭会话工厂
       sessionFactory.close();
上一篇:Codeforces Round #555 (Div. 3) A B C1(很水的题目)


下一篇:网易云通过KCSP认证,云原生技术实力再获认可