读书人

hibernate为啥有两个配置文件

发布时间: 2012-08-29 08:40:14 作者: rapoo

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呢? 能省事就省事呗. 正规点就是简化书写.

读书人网 >编程

热点推荐