Gentuzos
Gentuzos

Reputation: 265

java.lang.ClassNotFoundException: org.hibernate.HibernateException

I am running a web application with hibernate and got stuck at this exception. Any help please?

java.lang.ClassNotFoundException: org.hibernate.HibernateException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at com.forum.dao.TopicDAO.findAll(TopicDAO.java:43) at com.forum.servlets.Accueil.doGet(Accueil.java:23) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Here is TopicDAO.findALL()

public static List<Topic> findAll() {

    Session  s = HibernateUtils.getSession(); //TopicDAO.java:43
    Transaction tx = s.beginTransaction();
    List<Topic> objects = null;

    Query q = s.createQuery("from Topic");
    objects = q.list();
    tx.commit();

    return objects;
}

And, here is my servlet.doGet()

public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
    HttpSession session = request.getSession();

    TopicDAO td = new TopicDAO();
    List<Topic> listTopics = td.findAll();

    session.setAttribute( ATT_LIST_TOPICS, listTopics );

    this.getServletContext().getRequestDispatcher( ACCUEIL ).forward( request, response );
}

Here is my added Hibernate libraries:

hibernate structure

Upvotes: 7

Views: 83263

Answers (5)

Raul Acu
Raul Acu

Reputation: 171

[For Eclipse IDEs] I have ran into similar problems, I've tried everything from numerously maven clean, installs and updates to switching workspaces, cleaning the classpath or switching java version but it could only be solved as it follows:

-this exception might also be the result of manually creating the Tomcat server where the required dependencies are not deployed onto, even if the required jars are in place within the current project. In order to do so you must fix the server's configuration and referenced projects.

Servers Properties

Runnings configuration

Upvotes: 0

shubham grover
shubham grover

Reputation: 1

try adding jar files in webContent/WEB-INF/lib. That should work most probably. Sometimes hibernate is unable to find the required jar files. So, you have to add jar files and provide the correct path for that.

Upvotes: -1

Keelean
Keelean

Reputation: 58

Sometimes it could be as as result of conflicting hibernate libraries in your local maven repo. I had this issue and after trying everything suggested here which did not work for me, I had to resort to deleting everything in the hibernate folder which contain multiple versions of hibernate in my maven local repo. And after that everything started working fine for me

Upvotes: 0

justADreamer
justADreamer

Reputation: 295

Explanation:

  • A ClassDefNotFound exception means that your program was unable to find a required .class file from the referenced libraries.

  • In your case the hibernateX.jar file isn't packaged inside your war file.

  • What you need to do is to add it to the WEB-INF/lib folder of your war file.

Solution (using IntelliJ):

  1. open up project structure

  2. select Artifacts from the left side options

  3. from your war file in the OutputLayout tab browse to WEB-INF/lib

  4. add the library containing hibernateX.jar into the folder

  5. redeploy your project.

Solution (using Eclipse):

  1. Simply drag and drop the jar to WEB-INF/lib

Upvotes: 18

wmac
wmac

Reputation: 1063

I see a few of the libraries are missing. I have these and it works just fine. Btw. what database do you use? PostgreSQL? Otherwise you need to also include the JDBC driver for your database. Please note that some of these are required for hibernate use through JPA.

enter image description here

Upvotes: 1

Related Questions