1)Configuration
在没有引入hibernate.cfg.xml之前就产生了,当时需要有一个hibernate.properties的文件来起xml文件的功能,但又不能完全承载,所以就需要Configuration对象
Configuration cfg=new Configuration().addResource("hibernate.properties");
2)创建SessionFactory
SessionFactory sf=cfg.bulidSessionFactory()
到XML阶段,直接可以写为SessionFactory sf=new Configuration().configure().buildSessionFactory();
如果核心文件不叫hibernate.cfg.xml,则在configure中传入字符串参数,指定文件名。
3)打开session
Session session=SessionFactory.openSession();
4)开始一个事务
Transaction tx=session.beginTransaction();
5)持久化操作
save/update/delete/find/操作Hibernate的关键
6)提交事务
tx.commit();
7)关闭session
session.close();