My project is like this:
/src/main/java
-thegamers
-app.java
-hibernateutil.java
can someone tell me where to put th
if it is not web project then do explicitly like that
new Configuration().configure( "pth/to/hibernate.cfg.xml").buildsessionfactory()
Hope this may help
@SiB pointed a link(mkyong's web site). It is explained well there.
Place hibernate.cfg.xml
under src/
folder or explicitly mention the path in code as:
new Configuration.configure("path of hibernate.cfg.xml").buildsessionfactory()
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.
I'm using maven, and it didn't work for me until I put hibernate.cfg.xml in src/main/resources
.
At the root of your project: /src
(at leat as default)
How to know if /src
is the sources dir?
When you create a new Java class, it is contained in a package (normally it is called as the same name of the dir where it is created). So, in your class declarion you can see something like this:
package foo;
class MyClass{
In default IDE settings, the class should found under /src/foo/MyClass.java
. As you can see, in this scenario /src
acts as root sources dir.
CMD+N/CTR+N while you are on Eclips, it will open a dialog-box there you have to dubbel click on the Hibernate folder. It will open a list of files with the XML extenuation. Select the cfg.xml and click on continue and when you are done! click on finish. Eclips will now add the Class name with the cfg.xml file and show it under the SRC folder. GB