As you can see I have a HibernateUtil that I use to persist data to my database. The same code I use in my userBean.save method is the same code I use in my junittest. In my junit test below it works perfectly. However when I try to call the userBean.save method in my commandbutton it gives me an error, org.hibernate.HibernateException: /hibernate.cfg.xml not found.
After some debugging I can tell you the error happens in hibernateUtil class, configuration.configure().addAnnotatedClass(userBean.class);
If I change the commandbutton action to welcome, which is the name of my welcome page, the form works fine by redirecting me to the welcome page and it outputs the bean values on the page. This means , as far as I'm concerned ,that the bean is been initialized correctly. This is very confusing, why is it working in my junit test and not on my jsf page?
As I said the problem is comming from configuration.configure().addAnnotatedClass(userBean.class);
So I took my debugger through and copied the console outputs from when we cross this piece of code. Here is the output from the working Junit test
Here is the code from the not working jsf running
Here is an image of my folder structure showing my src and deployed resources as well
Excellent, that solved the problem there.
I needed to have my hibernate.cfg.xml in the web-inf/classes folder.
However I am now experiencing a similar problem
On line 13 of my hibernateUtill class
I had this problem before and I fixed it by editing my persistence.xml. I tried moving the persistence.xml into the web-inf/classes folder in case it was a classpath issue again. However it did not solve the problem.My folder structure is the same as the image above except for hibernate.cfg.xml is now under the classes folder.
Again its working fine in my unit test but its failing on the live run.
Yes, you were right. I had to put my Derbyclient.jar
I'm a little disappointed in this because I was hoping Maven would have handled this for me, I think I have alot more reading to do here.
This is all working now, but I'm a bit confused. Why was Junit able to function properly and execute the code if it wasn't on my classpath.
Is it because Junit happens runs at compile time therefore never needs to be deployed to jboss?