title: No Persistence provider for EntityManager Hibernate 5
body: <p>I have the following project structure which is a multi-module maven project. My issue is in the persistence configuration (located in the model module). It generates my war without returning errors but when it comes to instanciate the EntityManager, it throws a <code>javax.persistence.PersistenceException: No Persistence provider for EntityManager named myPersistence</code></p>
  
  <pre><code>PARENT
  |
  |-DATABASE
  | └ src/main/
  | └ pom.xml
  |
  |-MODEL
  | |- src/main
  | |  └ java/
  | |    └ .../JPAUtil.java
  | |  └ ressources
  | |    └ META-INF
  | |      └ persistence.xml
  | └ pom.xml
  |
  |-WS
  | └ src/main/
  | └ pom.xml
  |
  └ pom.xml
  </code></pre>
  
  <p><strong>persistence.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
  
      &lt;persistence-unit name="myPersistence" &gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
  
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/mySchema" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="user" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="password" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>PARENT - pom.xml</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;my.group.id&lt;/groupId&gt;
      &lt;artifactId&gt;parent&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
  
      &lt;modules&gt;
          &lt;module&gt;modele&lt;/module&gt;
          &lt;module&gt;database&lt;/module&gt;
          &lt;module&gt;WS&lt;/module&gt;
      &lt;/modules&gt;
  
      &lt;properties&gt;
          &lt;!--  encoding--&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;!--java version --&gt;
          &lt;java-version&gt;1.7&lt;/java-version&gt;
  
          &lt;!-- plugin versions --&gt;
          &lt;war-plugin-version&gt;2.4&lt;/war-plugin-version&gt;
          &lt;compiler-plugin-version&gt;3.1&lt;/compiler-plugin-version&gt;
  
          &lt;!-- dependency versions --&gt;
          &lt;javaee-api-version&gt;7.0&lt;/javaee-api-version&gt;
  
      &lt;/properties&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;junit&lt;/groupId&gt;
                  &lt;artifactId&gt;junit&lt;/artifactId&gt;
                  &lt;version&gt;${junit-version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;joda-time&lt;/groupId&gt;
                  &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
                  &lt;version&gt;2.0&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
                  &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
                  &lt;version&gt;5.3.1.Final&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
                  &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
                  &lt;version&gt;5.3.1.Final&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-json&lt;/artifactId&gt;
                  &lt;version&gt;1.8&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;mysql&lt;/groupId&gt;
                  &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                  &lt;version&gt;5.1.37&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
                  &lt;artifactId&gt;poi&lt;/artifactId&gt;
                  &lt;version&gt;3.9&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;log4j&lt;/groupId&gt;
                  &lt;artifactId&gt;log4j&lt;/artifactId&gt;
                  &lt;version&gt;1.2.17&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.persistence&lt;/groupId&gt;
                  &lt;artifactId&gt;javax.persistence-api&lt;/artifactId&gt;
                  &lt;version&gt;2.2&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;my.group.id&lt;/groupId&gt;
                  &lt;artifactId&gt;database&lt;/artifactId&gt;
                  &lt;version&gt;${project.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;my.group.id&lt;/groupId&gt;
                  &lt;artifactId&gt;modele&lt;/artifactId&gt;
                  &lt;version&gt;${project.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;my.group.id&lt;/groupId&gt;
                  &lt;artifactId&gt;WS&lt;/artifactId&gt;
                  &lt;version&gt;${project.version}&lt;/version&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;build&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;!-- compiler plugin --&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;${compiler-plugin-version}&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;source&gt;${java-version}&lt;/source&gt;
                          &lt;target&gt;${java-version}&lt;/target&gt;
                          &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  
                  &lt;plugin&gt;
                      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                      &lt;version&gt;${war-plugin-version}&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
  
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>MODELE - pom.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;my.group.id&lt;/groupId&gt;
          &lt;artifactId&gt;parent&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/parent&gt;
      &lt;artifactId&gt;modele&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;javax.persistence-api&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;joda-time&lt;/groupId&gt;
              &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I have explored several solutions including:<br/></p>
  
  <ul>
  <li>changing persistence.xml file's location<br/></li>
  <li>changing the provider (org.hibernate.jpa.HibernatePersistenceProvider)<br/></li>
  <li>using c3p0 provider<br/></li>
  <li>including target/modele-1.0.jar into persistence.xml<br/></li>
  <li>including  into persistence.xml<br/></li>
  </ul>