0

i created new simple web app projected with hibernate 5 , Tomcat9 server. when run project it show following error.

  Exception
 javax.servlet.ServletException: Servlet execution threw an exception
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


  Root Cause
  java.lang.NoSuchMethodError: 
  org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init> 
 (Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V

 org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl
 .generateDefaultReflectionManager(MetadataBuilderImpl.java:741)

 org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl
 .<init>(MetadataBuilderImpl.java:714)
  org.hibernate.boot.internal.MetadataBuilderImpl.<init > 
  (MetadataBuilderImpl.java:126)

  org.hibernate.boot.MetadataSources.getMetadataBuilder
 (MetadataSources.java:135)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:654)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
org.serv.Controller.doPost(Controller.java:45)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

here is servlet which throws exception

    package org.serv;

    import java.io.IOException;


   import javax.servlet.ServletException;
   import javax.servlet.annotation.WebServlet;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;

  import org.hibernate.HibernateException;
  import org.hibernate.Session;
   import org.hibernate.SessionFactory;
 import org.hibernate.cfg.Configuration;
 import org.pojo.PhoneBook;



 @WebServlet("/Controller")
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public Controller() {
    super();
    // TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response )throws ServletException, IOException{

    doPost(request,response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

PhoneBook book = new PhoneBook();
    book.setName(request.getParameter("name"));
    book.setPhone(Integer.parseInt( request.getParameter("number")));
    book.setAddress(request.getParameter("address"));
    try {
    SessionFactory sf = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
    Session sess = sf.openSession();
    sess.beginTransaction();
    sess.save(book);
    sess.close();
    }catch(HibernateException e ) {e.printStackTrace();System.err.println("Session problem ");}

}//end doPost

}//servlet

Here are library list which been listed.

enter image description here

and here is hibernate.cfg.xml file structure

    <?xml version='1.0' encoding='utf-8'?>

     <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

  <hibernate-configuration>

<session-factory>

    <!-- Database connection settings -->
    <property 
   name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property 
  name="connection.url">jdbc:mysql://localhost:3306/stockdb</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>


    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Disable the second-level cache  -->
    <property 
  name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider
 </property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

    <!--  Name the Annotated Entity Class -->
    <mapping class= "org.pojo.Product"/>
    <mapping class= "org.pojo.Catagories"/>
    <mapping class= "org.pojo.ProductDetail"/>
    <mapping class= "org.pojo.Supplier"/>
    <mapping class= "org.pojo.Staff"/>
    <mapping class= "org.pojo.Customer"/>
    <mapping class= "org.pojo.PurchaseInvoice"/>
    <mapping class= "org.pojo.SaleInvoice"/>
    <mapping class= "org.pojo.Stock"/>
    <mapping class= "org.pojo.PhoneBook"/>
</session-factory>

 </hibernate-configuration>

I have been searched everywhere and also search stackover flow but didn't found solution.

3
  • 1
    did you look at: stackoverflow.com/questions/38407235/… looks like it could be the same issue (try to remove the hibernate-annotations...jar) Commented Nov 2, 2018 at 18:55
  • I already check that link but I don't have maven in my project. i pasted jar picture in above question and that looks ok .. but problem is still there. Commented Nov 3, 2018 at 19:22
  • yeah, you do not use maven, but you have the same dependecies in your project. (hibernate annotations and hibernate core) maybe it works if you remove hibernate-annotations, like it did in the other case Commented Nov 4, 2018 at 12:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.