title: Hibernate Error java.lang.NoSuchMethodError
body: <p>I'm using Jersey as Rest web service and Hibernate entity manager to persist JPA models. and I'm using Tomcat 8 as container.</p>
  
  <p>Here is the content of the persistence.xml file :</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0"&gt;
  
      &lt;persistence-unit name="manager1" transaction-type="JTA"&gt;
  
          &lt;properties&gt;
  
              &lt;!--PostgreSQL--&gt;
              &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres"/&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
              &lt;property name="hibernate.connection.username" value="postgres"/&gt;
              &lt;property name="hibernate.connection.password" value="postgres"/&gt;
              &lt;property name="hibernate.archive.autodetection" value="class"/&gt;
              &lt;property name="hibernate.id.new_generator_mappings" value="true"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
              &lt;property name="hibernate.ejb.metamodel.generation" value="disabled"/&gt;
              &lt;property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy"/&gt;
              &lt;property name="hibernate.show_sql" value="true"/&gt;
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>And my Rest call is as simple as this : </p>
  
  <pre><code>@GET
  @Path("/")
  public Response test() {
  
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");
  
      return Response.status(Response.Status.OK).build();
  }
  </code></pre>
  
  <p>and here is my web.xml file </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
    &lt;display-name&gt;Restful Web Application&lt;/display-name&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;jersey-serlvet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
        &lt;param-value&gt;ca.products.services&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;com.sun.jersey.api.json.POJOMappingFeature&lt;/param-name&gt;
  
        &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;jersey-serlvet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>But it gives me this error : </p>
  
  <pre><code>type Rapport d''exception
  
  message java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.&lt;init&gt;(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V
  
  description Le serveur a rencontré une erreur interne qui l''a empêché de satisfaire la requête.
  
  exception
  
  javax.servlet.ServletException: java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.&lt;init&gt;(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V
      com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  cause mère
  
  java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.&lt;init&gt;(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V
      org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.generateDefaultReflectionManager(MetadataBuilderImpl.java:736)
      org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.&lt;init&gt;(MetadataBuilderImpl.java:709)
      org.hibernate.boot.internal.MetadataBuilderImpl.&lt;init&gt;(MetadataBuilderImpl.java:127)
      org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
      org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.&lt;init&gt;(EntityManagerFactoryBuilderImpl.java:185)
      org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
      org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
      org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
      org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
      org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
      ca.products.services.RestServices.test(RestServices.java:42)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:497)
      com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
      com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
      com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
      com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
      com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
      com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
      com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
      com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
      com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
      com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
      com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>I was not be able to figure out where is the problem !! any help ?</p>
  
  <p>as suggested, here is the mvn dependency:tree log : </p>
  
  <pre><code>[INFO] ca.products.jpa_module:jpa_module:jar:1.0-SNAPSHOT
  [INFO] +- org.hibernate:hibernate-core:jar:5.0.7.Final:compile
  [INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
  [INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
  [INFO] |  +- org.javassist:javassist:jar:3.18.1-GA:compile
  [INFO] |  +- antlr:antlr:jar:2.7.7:compile
  [INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
  [INFO] |  +- org.jboss:jandex:jar:2.0.0.Final:compile
  [INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
  [INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
  [INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
  [INFO] +- org.hibernate:hibernate-annotations:jar:3.5.6-Final:compile
  [INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
  [INFO] |  \- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
  [INFO] +- org.hibernate:hibernate-search-orm:jar:5.5.2.Final:compile
  [INFO] |  \- org.hibernate:hibernate-search-engine:jar:5.5.2.Final:compile
  [INFO] |     +- org.apache.lucene:lucene-core:jar:5.3.1:compile
  [INFO] |     +- org.apache.lucene:lucene-backward-codecs:jar:5.3.1:compile
  [INFO] |     +- org.apache.lucene:lucene-misc:jar:5.3.1:compile
  [INFO] |     +- org.apache.lucene:lucene-analyzers-common:jar:5.3.1:compile
  [INFO] |     \- org.apache.lucene:lucene-facet:jar:5.3.1:compile
  [INFO] |        \- org.apache.lucene:lucene-queries:jar:5.3.1:compile
  [INFO] +- org.hibernate:hibernate-entitymanager:jar:5.0.7.Final:compile
  [INFO] +- org.hibernate:hibernate-ehcache:jar:5.0.7.Final:compile
  [INFO] |  \- net.sf.ehcache:ehcache-core:jar:2.4.3:compile
  [INFO] +- com.google.inject.extensions:guice-assistedinject:jar:4.0:compile
  [INFO] |  \- com.google.inject:guice:jar:4.0:compile
  [INFO] |     +- javax.inject:javax.inject:jar:1:compile
  [INFO] |     +- aopalliance:aopalliance:jar:1.0:compile
  [INFO] |     \- com.google.guava:guava:jar:16.0.1:compile
  [INFO] +- com.google.inject.extensions:guice-persist:jar:4.0:compile
  [INFO] +- log4j:log4j:jar:1.2.17:compile
  [INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.12:compile
  [INFO] +- org.slf4j:slf4j-api:jar:1.7.12:compile
  [INFO] \- commons-logging:commons-logging:jar:1.1.1:compile
  </code></pre>