首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

hibernate为啥有两个配置文件

2012-08-29 
hibernate为什么有两个配置文件????? hibernate有两个配置文件 , 一个是hibernate.cfg.xml一个是hibernate

hibernate为什么有两个配置文件

????? hibernate有两个配置文件 , 一个是hibernate.cfg.xml一个是hibernate.properties. 一般代码是这样写:

新建configration读配置文件

----->Configuration conf = new Configuration();

//这里默认读取hibernate.properties配置文件.

------->conf.configure();

// 这里不写文件名就默认读取hibernate.cfg.xml文件.如有相同会覆盖hibernate.properties

configuration产生sessionFactory------->sessionFactory = conf.buildSessionFactory();

sessionFactory开启一个session------->sessionFactory.openSession();

为什么要有两个配置文件呢.这里再配置hibernate.cfg.xml是为了完成hibernate.properties完成不了的事情, 一般就是读取*.hbm.xml映射文件.那为什么不只写一个properties呢? 能省事就省事呗. 正规点就是简化书写.

热点排行