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
The config file hibernate.cfg.xml
needs to be on the classpath
.
This can be accomplished in different ways, depending on your project.
For a web-app WAR project (you are running the program in a Servlet container):
placing it in WEB-INF/classes
will work as files in WEB-INF/classes
are visible on the classpath when app is running in container.
For a Maven-style project (not running the program in a Servlet container): placing it in /src/main/resources/
will work
For otherwise, try in the src/
directory.