Hibernate 中配置主要分为两种:1.包含Hibernate于数据库的基本连接信息,在hibernate工作的初始阶段,这些信息先后被加载到Configuration和SessionFactory实例。Hibernate.properties由于该文件没有提供Hiberna ...
Hibernate 中配置主要分为两种:
1.包含Hibernate于数据库的基本连接信息,在hibernate工作的初始阶段,这些信息先后被加载到Configuration和SessionFactory实例。
Hibernate.properties
由于该文件没有提供Hibernate的映射文件方式所以需要利用addResource()方法添加映射文件,利用addClass()直接添加持久化类
注解:可以利用Hibernate.properties连接数据库,利用Hibernate.cfg.
private static void init(){ Configuration cfg = new Configuration(); try{ properties p = new Properties(); p.load(HibernateSessionFactory.class.getResourceAsStream("hibernate.properties")); cfg.setProperties(p); }catch(IOException e){ e.printStackTrace(); throw new RunTimeException("fail load the hibernate.properties"); } cfg.configure("hibernate.cfg.); }
原标题:Hibernate configuration files
关键词:Hibernate
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。