Abdul Majid Bajwa
Abdul Majid Bajwa

Reputation: 159

Initial SessionFactory creation failed./resources/hibernate.cfg.xml not found

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

enter image description here

Upvotes: 0

Views: 959

Answers (2)

question_maven_com
question_maven_com

Reputation: 2473

  • Move Java Sources in src/main/java
  • *.xml in src/main/resources

To meet the standards of MAVEN , like that XML will be added automatically at CLASSPATH

Upvotes: 1

JB Nizet
JB Nizet

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

Related Questions