Hibernate异常之org.hibernate.HibernateException: /hibernate.cfg.xml not found
程序员文章站
2022-04-13 16:03:14
...
1、异常描述
org.hibernate.HibernateException: /hibernate.cfg.xml not found
备注:
此处hibernate版本号:3.6.10.Final
2、分析原因
一下是hibernate创建session工厂的示例代码:
private static Configuration configure;
private static SessionFactory sessionFactory;
static{
try {
// 实例化配置对象
configure = new Configuration().configure();
// 利用配置对象创建session工厂
sessionFactory = configure.buildSessionFactory();
} catch (HibernateException ex) {
throw new ExceptionInInitializerError(ex);
}
}
在以上示例代码中,当实例化配置对象时,hibernate框架会查找一个名为 hibernate.cfg.xml 的配置文件。如果找不到该配置文件,就会报此错
3、解决方式
情况1:查看hibernate的配置文件的文件名是否出错
情况2:查看hibernate.cfg.xml放置的位置是否正确
如果是普通的java项目(java web项目),hibernate.cfg.xml必须放置的需要引用它的类的外层()推荐直接放置在src根目录
如果是maven项目,hibernate.cfg.xml直接放在 src/main/resource 目录下即可
此文希望可以帮助到大家。如有错误,请指教。
如果大家还有其他的情况或者好的解决方法,也望指教,感谢阅读。
上一篇: 求各位数之和
下一篇: appfuse hbm2ddl出错
推荐阅读
-
【问题解决】org.hibernate.HibernateException: hibernate.cfg.xml not found
-
Hiberante异常之org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
hibernate异常Found shared references to a collection
-
org.hibernate.HibernateException: Found shared references to a collection: com.jinyi.ihome.module.ex...
-
Hibernate异常之org.hibernate.HibernateException: /hibernate.cfg.xml not found
-
架构师之spring----spring异常java.lang.IllegalStateException: Ambiguous mapping found.
-
架构师之spring----spring异常java.lang.IllegalStateException: Ambiguous mapping found.
-
Hibernate异常Found shared references的解决办法
-
Hibernate异常之 org.hibernate.LazyInitializationException: failed to lazily initialize a collecio....