Reputation: 159
I have created Simple project using Maven Hibernate, But project gives me following error:
Initial SessionFactory creation failed./resources/hibernate.cfg.xml not found
org.hibernate.HibernateException: /resources/hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1453)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1475)
at Code.CourseDaoImp.<clinit>(CourseDaoImp.java:16)
at Code.CourseServiceImp.processCourse(CourseServiceImp.java:10)
at Code.app.main(app.java:21)
Exception in thread "main" java.lang.ExceptionInInitializerError
at Code.CourseDaoImp.<clinit>(CourseDaoImp.java:22)
at Code.CourseServiceImp.processCourse(CourseServiceImp.java:10)
at Code.app.main(app.java:21)
Caused by: org.hibernate.HibernateException: /resources/hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1453)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1475)
at Code.CourseDaoImp.<clinit>(CourseDaoImp.java:16)
... 2 more
Upvotes: 0
Views: 959
Reputation: 2473
To meet the standards of MAVEN , like that XML will be added automatically at CLASSPATH
Upvotes: 1
Reputation: 692161
resources is one of the sources folder of your project. This means that everything it contains is at the roor of the classpath (in the default package). So the code you need is
sessionFactory = new Configuration().configure("hibernate.cfg.xml");
Upvotes: 1