This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi All, I am working on websphere 4 and have created a Java application.
My root folder is FirstHibernateExample and it is under C:\danny\hibernate\FirstHibernateExample\ my java,class and xml files are under C:\danny\hibernate\FirstHibernateExample\src\com\test\example\
When I compile the java files everything is fine. When I run the application I get the following error : net.sf.hibernate.HibernateException: hibernate.cfg.xml not found. In my code I have specified private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
I have tried placing the hibernate.cfg.xml in all the locations , but still the error exists. Can Someone help me on this Thanks in Advance Regards Danny
The simplest thing to do is put your hibernate.cfg.xml file in your src folder (check that your build process copies it to a similar location wrt class files in your directory structure/jar/war etc...) and implicitly access it via the no-argument configure method:There's no need to mention a path in your code -- this is the default location.
I am in the ejb container of Websphere 22.214.171.124 and can not find where to put the hibernate.cfg.xml file. Is this a websphere issue? I have worked a full 2 days on this and can not figure out what to do.
1/31/06 20:18:38:334 CST] 785e785e SystemOut O Exception creating SessionFactory object: /hibernate.cfg.xml not found [1/31/06 20:18:42:781 CST] 785e785e Configuration I net.sf.hibernate.cfg.Configuration configuring from resource: /hibernate.cfg.xml
[1/31/06 20:18:42:781 CST] 785e785e Configuration I net.sf.hibernate.cfg.Configuration Configuration resource: /hibernate.cfg.xml
[1/31/06 20:18:42:781 CST] 785e785e Configuration W net.sf.hibernate.cfg.Configuration /hibernate.cfg.xml not found
Garth IBM Certified Enterprise Developer WSAD 5.x [ January 31, 2006: Message edited by: garth schneider ]
Joined: Mar 20, 2002
Just figured it out.
File f = new File("C:\\ProjHibernatedEJB\\ProjHiberFacade\\ejbModule\\hibernate.cfg.xml"); sessions = new Configuration().configure(f).buildSessionFactory(); //
I hardcoded the absolute path in a file object and passed it to configure. It is a sad thing to have to do but it works. And I am not proud. Garth
[ January 31, 2006: Message edited by: garth schneider ] [ January 31, 2006: Message edited by: garth schneider ]
After 2 days of fighting this issue I put it everywhere. In the regular Java environment it worked great in the default package. I did not have to pass anything to the configure method. When I brought it into the EJB 2.0 container it did not work in the default package. I tryed to create a regular java jar and put it in the default area. I tryed putting it in its own place in a package and then pass that directory string to the configure method. I even changed the name of the cfg file and reference it by another name. It just did not work. I have a PMR open with IBM now and we will see if I can get anything from that. It works good in JBoss I hear say. I tryed it in both WSAD 5.1.2 and RAD 6.0. As you can see from the below area it is in the default directory of the EJB area "ejbModule" area. I also tryed putting it above that and it did not work. File f = new File("C:\\ProjHibernatedEJB\\ProjHiberFacade\\ejbModule\\hibernate.cfg.xml"); sessions = new Configuration().configure(f).buildSessionFactory();
SCJP (Sun Certified Java Programmer) IBM #486 Object Oriented Analysis and Design with UML IBM #283 Specialist for the VisualAge for Java 4.0 IBM Solution Developer for VisualAge for Java 4.0 IBM #157 Specialist for the WebSphere Studio Application Developer 4.0 IBM Solution Developer for WebSphere Studio Application Developer 4.0 IBM #484 Enterprise Connectivity with Java Technology J2EE 1.3 IBM #287 Enterprise Application Development with WebSphere Studio V5.0. IBM Certified Enterprise Developer - WebSphere Studio, V5.0 [ February 01, 2006: Message edited by: garth schneider ]
We are running a struts application in Tomcat container of JBoss 4.0.3 SP1. We had the same problem. Here is how we fixed it... # Copied hibernate.cfg.xml to the JBoss/bin directory. # Added "." to my classpath. # Called startup batch file (run.bat) from JBoss/bin directory.
/hibernate.cfg.xml not found .. error in Jboss 3.2 Tomcat 4.1. Hope someone finds this fix useful.
Only getting the error on one development PC, other dev PCs and linux deploy server do not have error when the file is in /WEB_INF/classes - a strange one. To fix I put the file everywhere else I could think of eg. /WEB-INF; /; web-inf/classes/resources; hibernate package folder and error disappeared. Then I narrowed it down to the / <web root>. For some reason hibernate is looking here for the config file. So now I have a security problem with a config file in web root, and another unrelated hibernate error.
Joined: Apr 05, 2006
the above fix is not a fix. Putting cfg in web root means that cfg then can't find anything else. still working on it unfortunately.
By default hibernate.cfg.xml is expected to be at the root of your classpath. So if that is a Web Application then the root is WEB-INF/classes. All Hibernate does is calls getResourceAsStream("/hibernate.cfg.xml") - no different than getting any other resource on the classpath. If you've put it there and it does not work, then your have another problem that is nothing to do with Hibernate.
Joined: Apr 05, 2006
I see what you mean about the problem not being hibernate. More likely to be a Jboss classloader issue. But then how do you explain that Jboss is loading 50 other jars and none of them have classpath issues? Also how do you explain so many others on web having same issue?
I ended up 'fixing' the issue by passing -verbose:class option to the jvm when starting Jboss. I know this is only supposed to print classes loading but it did fix it. Then I took it away again and the problem was gone. And to prove it was not hardware/os, the same happened on 2 pcs. This bug is candidate for the x-files.
You don't have to hard code the absolute path of the hibernate.cfg.xml. You can access it by relative path. Assuming your hibernate.cfg.xml is in src folder under com/hibernateweb/config/hibernate.cfg.xml, you can do the following:
my java,class and xml files are under
When I compile the java files everything is fine.
When I run the application I get the following error :
net.sf.hibernate.HibernateException: hibernate.cfg.xml not found.
In my code I have specified
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
try removing forward slash from the location, i.e.