hibernatehibernate.cfg.xml

Where to place hibernate.cfg.xml?


My project is like this:

/src/main/java
     -thegamers
         -app.java
         -hibernateutil.java

can someone tell me where to put the hibernate.cfg.xml?

because I'm getting this error:

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

Solution

  • The config file hibernate.cfg.xml needs to be on the classpath.

    This can be accomplished in different ways, depending on your project.