java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider - PullRequest
0 голосов
/ 02 ноября 2018

Я создал новое простое веб-приложение, спроектированное с сервером hibernate 5, Tomcat9. при запуске проекта показывается следующая ошибка.

  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)

вот сервлет, который выдает исключение

    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

Вот список библиотек, которые были перечислены.

enter image description here

а вот структура файла hibernate.cfg.xml

    <?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>

Меня искали везде, а также поиск по стеку, но я не нашел решения.

...