Java.lang.ClassNotFoundException: org.hibernate.HibernateException

I am running a hibernated web application and are stuck with 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 (WebappClass15o 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) in javax.servlet.http.HttpServlet.service (HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChaindo .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:4 72) 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.AccessLogVal .invoke (AccessLogValve.java:953) on org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:118) on org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:408) on org. apache.coyote.http11.AbstractHttp11Processor.process (AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process (AbstractProtocol.javahaps89) at org.apache.tomcat.util.net.JIEndpoint. run (JIoEndpoint.javahaps12) in java.util.concurrent.ThreadPoolExecutor.runWorker (Unknown source) in java.util.concurrent.ThreadPoolExecutor $ Worker.run (Unknown source) in java.lang.Thread.run (Unknown and Točník)

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 are my added Hibernate libraries:

hibernate structure

+7
java-ee tomcat hibernate servlets
source share
5 answers

Explanation:

  • The ClassDefNotFound exception means that your program could not find the required .class file from the referenced libraries.

  • In your case, the hibernateX.jar file is not packaged inside your war file.

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

Solution (using IntelliJ):

  • open project structure

  • Select Artifacts on the left.

  • from your war file, on the OutputLayout tab, find WEB-INF/lib

  • add the library containing hibernateX.jar to the folder

  • relocate the project.

Solution (using Eclipse):

  • Just drag the jar to WEB-INF/lib
+17
source share

I see that some of the libraries are missing. I have everything and everything works fine. Btw. which database are you using? PostgreSQL? Otherwise, you also need to enable the JDBC driver for your database. Please note that some of them are required for use in sleep mode via JPA.

enter image description here

+1
source share

This can sometimes be the result of conflicting hibernation libraries in your local maven repository. I had this problem, and after I tried everything suggested here, which did not work for me, I had to resort to deleting everything in the sleep mode folder containing several versions of sleep mode in my local maven repo. And after that, everything began to work fine for me.

0
source share

try adding jar files to webContent/WEB-INF/lib . This should work most likely. Sometimes hibernate cannot find the necessary jar files. So, you need to add jar files and specify the correct path for this.

0
source share

[For the Eclipse IDE] I encountered similar problems, I tried everything: from maven clean, install and upgrade to switch workspaces, clear class paths or switch Java versions, but this can only be solved as follows:

The -this exception can also be the result of manually creating a Tomcat server on which the necessary dependencies are not deployed, even if the current project has the necessary JAR files. To do this, you need to fix the server configuration and reference projects.

Server Properties

Move Configuration

0
source share

All Articles