学习hibernate笔记

来源:互联网 发布:域名注册机构有哪些 编辑:程序博客网 时间:2024/06/04 18:25

hibernate

1.首先要配置hibernate.xml 配置文件,然后建立每个实体类的映射文件 xxxx.hbm.XML。
<class name ="类名" table ="表名">
<id name = "实体类中的主键名" column name = "数据库中的主键名">
<propert name = "实体类中属性的名字" column name ="数据库表中属性的名字 ">
然后要让hibernate.xml能够找到映射文件,<mapping resource="com/bjsxt/hibernate/model/Student.hbm.xml"/>
2.准备工作做好之后,在写测试类时先要拿到Configuration cfg (org.cfg.configuration 用来读配置文件的),然后通过cfg.configur返回一个
找到配置文件自身的configuration.sessioFactory(sf)、然后 Session session = sf.openSession,放到事务transaction中开始
0 0
原创粉丝点击