这两天再看hibernate,就自己总结了hibernate对jdbc的封装过程。

1.通过Configuration().configure();读取并解析hibernate.cfg.xml配置文件
2.由hibernate.cfg.xml中的<mapping resource="com/xx/User.hbm.xml"/>读取并解析映射信息
3.通过config.buildSessionFactory();//创建SessionFactory
4.sessionFactory.openSession();//打开Sesssion
5.session.beginTransaction();//创建事务Transation
6.persistent operate持久化操作
7.session.getTransaction().commit();//提交事务
8.关闭Session

9.关闭SesstionFactory

这里是没有使用配置文件,手写的文件:



其实我的IDE是Myeclipes的里面有自动生成hibernate文件的工具。仔细的看看系统自动生成的代码:

配置文件:

映射文件:

POJO文件和DAO文件:

SessionFactory和Session类文件:就是建立加载配置文件,数据库连接,打开事务等操作:






相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2021-09-04
  • 2021-05-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2021-05-19
相关资源
相似解决方案