1.搭建时候,需要添加jar包,hibernate.cfg.xml文件
以及每个实体类对应table的xx.class->xx.hbm.xml
2.旧版配置执行代码
//配置
Configuration config = new Configuration().configure();
//注册服务
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
//sessionfactory
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
session.beginTransaction();
Student s = new Student();
s.setName("yrj");
session.save(s);
session.getTransaction().commit();
session.close();
sessionFactory.close();
3.出现找不到类时候,工程的属性中buildpath可能有错误jar包,清除即可。