2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Where to place hibernate.cfg.xml

I am getting this exception.

Initial SessionFactory creation failed.org.hibernate.HibernateException: hibernate.cfg.xml not found
Exception in thread "main" java.lang.ExceptionInInitializerError
    at thegamers.HibernateUtil.buildSessionFactory(HibernateUtil.java:17)
    at thegamers.HibernateUtil.<clinit>(HibernateUtil.java:8)
    at thegamers.App.main(App.java:15)
Caused by: org.hibernate.HibernateException: hibernate.cfg.xml not found
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2149)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2130)
    at thegamers.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
    ... 2 more


Basically as per hibernate recommendation we can place this file in project class path location.

As per your exception it seem to be you kept it under any package from your project classpath.

From where you constructing the Configuration object just add your hibernate.cfg.xml file with given package name.

e.g suppose your file location is in com.test.hibernate then it should be like,

Configuration cfg = new Configure();


Answer is