学习hibernate笔记

xiaoxiao2021-02-28  132

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中开始
转载请注明原文地址: https://www.6miu.com/read-18183.html

最新回复(0)