I\'m trying to use hibernate with spring 3 mvc but at the moment I get this exception thrown. I think I need to define my hibernate.cfg.xml
somewhere, but not s
I have the same problem and moved hibernate.cfg.xml to the src/main/resources directory solved, it will be automatically be placed in /WEB-INF/classes.
hibernate.cfg.xml
should be in WEB-INF/classes
. Alternatively, you can load it from a custom location by passing the corresponding argument to the configure(..)
method.
If you using Maven you should put file hibernate.cfg.xml in following path /src/main/java/resources/hibernate.cfg.xml in Intellij IDEA. Then, in your run application class just insert line:
SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass().buildSessionFactory();
Instead of placing hibernate.cfg.xml
file under src/com/jr/hibernate/
directory, place it under src
directory. It will then automatically appear in WEB-INF/classes
directory, as mentioned by the folks here.
hibernate.cfg.xml
must be found in the root of the classpath when the webapp is started.
If you are using maven to build the project, put hibernate.cfg.xml in the src/main/resources
directory so that when you build the war package, it will be automatically be placed in /WEB-INF/classes
.
If not using maven, place the file directly in your WEB-INF/classes
directory.
In IntelliJ go to "Open Project Settings" >> Modules >> Hibernate and target your hibernate.cfg.xml file used in your project.