1.通過Configuration config = new Configuration().configure();//讀取并解析hibernate.cfg.xml配置文件
2.由hibernate.cfg.xml中的<mapping resource="com/xx/User.hbm.xml"/>讀取并解析映射信息
3.通過SessionFactory sf = config.buildSessionFactory();//創(chuàng)建SessionFactory
4.Session session = sf.openSession();//打開Sesssion
5.Transaction tx = session.beginTransaction();//創(chuàng)建并啟動事務Transation
6.persistent operate操作數(shù)據(jù),持久化操作
7.tx.commit();//提交事務
8.關閉Session
9.關閉SesstionFactory
// 創(chuàng)建數(shù)據(jù)庫事務(要么同時功要么同時失?。洪_發(fā)中除了查詢外都要用事務,事務有四個特性:原子性、一致性、隔離性、持久性