hibernate支持两种类型的配置文件,一种是hibernate.properties,另一种是hibernate.cfg.xml,采用不同的配置文件,创建Configuration的方式也不同
1.采用hibernate.properties作为配置文件,编码如下:
Configuration cfg=new Configuration();//默认加载hibernate.properties这个配置文件
cfg.addAnnotatedClass(*.class)
注:由于hibernate.properties的配置文件不提供配置加载持久化类的属性,所以必须手动调用Configuration对象的addAnnotatedClass或是addPackage()方法添加持久化类。
2采用hibernate.cfg.xml作为配置文件
Configuration cfg=new Configuration().configure()//configure()这个方法默认加载的是hibernate.cfg.xml这个配置文件
注:hibernate.cfg.xml提供了配置加载映射文件或者是加载持久化类的属性,所以无需通过编码方式手动添加。