0

I have tried to run my first web application using Hibernate,
(I started to learn how to use Hibernate only for a week, so be clement :( ) but I've a ClassNotFoundException and I don't understand the stack trace.

Can you help me?

GRAVE: Servlet.service() for servlet [it.tgi.cd.servlet2.CDOperationServlet2] in context with path [/CDStoreHibernateSpring] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
 at it.tgi.cd.connection2.DBConnection2.openConnection(DBConnection2.java:15)
 at it.tgi.cd.dao2.CDDAO2.searchCD(CDDAO2.java:17)
 at it.tgi.cd.servlet2.CDOperationServlet2.doGet(CDOperationServlet2.java:48)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Thread.java:745)
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
  • ClassNotFoundException is pretty clear in my opinion, what exactly you don't understand about it? – m0skit0 May 19 '15 at 13:11
  • be patient with me that I'm not very good at programming...where I should do it? – Excelsaga90 May 19 '15 at 13:13
  • Huh? I'm just asking: what exactly you don't understand about "Class Not Found" so we can clarify that for you :) Sorry if I sounded rude, that was not my intention. – m0skit0 May 19 '15 at 13:15
  • Nono I'm sorry, I can not write very well in English eheh I don't understand why it doesn't found that class.. – Excelsaga90 May 19 '15 at 13:20
  • Because some classes load other classes dynamically at runtime, not at compile time (in Java this is called [reflection](http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful)). This allows things like plugins. In this case `DBConnection2` cannot found this class the class `org.hibernate.cfg.Configuration`. Where do you have this class, can you find it? – m0skit0 May 19 '15 at 13:25

5 Answers5

0

Looks like you miss the hibernate-<version>.jar in your classpath. Download and add it to the classpath.

Jens
  • 67,715
  • 15
  • 98
  • 113
0

The missing class is in the hibernate-tools package. You can find the jar here:

http://mvnrepository.com/artifact/org.hibernate/hibernate-tools

Just make sure you use the proper version

breakline
  • 5,776
  • 8
  • 45
  • 84
0

I agree with Jens and I would approach it like this:

  1. Adopt a build system like Gradle or Maven)
  2. Put the Hibernate dependency in your build file with your project
  3. Build it

If you do these things, the build system will pull down Hibernate for you.

objectuser
  • 671
  • 6
  • 15
0

Try copying the hibernate jar files into WEB-INF\lib folder, just clean build to be sure and try again

acearch
  • 343
  • 1
  • 8
0

This error can happen when your hibernate jar files has not been exported with your web archive.

You can follow below steps if you are using Eclipse.

Right click the project -> Build Path -> Configure Build Path

In the list at left side click on Deployment Assembly. Click "Add" button. Select "Java Build Path Entries" and click next.

Now select your hibernate jar files or library. Click finish. Then click Ok. Restart the server if necessary.

Sagar Panda
  • 561
  • 3
  • 17