一:Hibernate运行过程:
1.通过Configuration().configure();读取并解析hibernate.cfg.xml配置文件
2.由hibernate.cfg.xml中的<mappingresource="com/xx/User.hbm.xml"/>读取并解析映射信息
3.通过config.buildSessionFactory();//创建SessionFactory
4.sessionFactory.openSession();//打开Sesssion
5.session.beginTransaction();//创建事务Transation
6.persistent operate持久化操作 //一般指Save这个方法
7.session.getTransaction().commit();//提交事务
8.关闭Session
9.关闭SesstionFactory
二:Hibernate操作
1 load和get的区别
load获得一个代理,只有id属性
get立即获得这个对象
2 getCurrentSession与openSession的区别
getCurrentSession从池获得一个,在事务回滚或者提交时自动关闭
openSeesion 重新创建一个,必须手动关闭
3 对象的三种状态
4 缓存
一级缓存 session级别的缓存,在事务范围内,由hibernate管理
二级缓存 sessionFactory级别的缓存,在线程范围内
5 关系映射
1对1
1对多
多对1
多对多
6 hibernate 5大接口
session,sessionfactory,configration,transcation和query