title: Embedded Derby with JPA: No Persistence Provider for EntityManager Named
body: <p>Yet Another. After 3.5 hours, I turn to stackoverflow to see if anyone can figure out why this error is occurring.</p>
  
  <pre><code>javax.persistence.PersistenceException: No Persistence provider for EntityManager named derby
  </code></pre>
  
  <p>The complete exception backtrace is as follows</p>
  
  <pre><code>javax.persistence.PersistenceException: No Persistence provider for EntityManager named derby
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      at mmis.mars.irs.mec.batch.DerbyTest.setup(DerbyTest.java:26)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  </code></pre>
  
  <p>The following jars are referenced. These are JPA, eclipselink, derby, and derbyclient. I do not think that derbyclient is needed, but I included it per another post about embedded derby with eclipselink.</p>
  
  <ul>
  <li>javax.persistence_2.1.0.v201304241213.jar</li>
  <li>eclipselink.jar</li>
  <li>derby.jar</li>
  <li>derbyclient.jar</li>
  </ul>
  
  <p>The following is the persistence.xml file. It is placed inside of the META-INF folder, which is in the root directory of the project. The META-INF folder is added as a source folder to the project.</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;persistence version="2.0"
          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"&gt;
  
          &lt;persistence-unit name="derby" transaction-type="RESOURCE_LOCAL"&gt;
              &lt;class&gt;JPA_class1&lt;/class&gt;
              &lt;class&gt;JPA_class2&lt;/class&gt;
              &lt;class&gt;JPA_class3&lt;/class&gt;
              &lt;class&gt;JPA_class4&lt;/class&gt;
  
              &lt;properties&gt;
                  &lt;property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" /&gt;
                  &lt;property name="javax.persistence.jdbc.url" value="jdbc:derby:thedb;create=true" /&gt;
              &lt;/properties&gt;
          &lt;/persistence-unit&gt;
      &lt;/persistence&gt;
  </code></pre>
  
  <p>META-INF inclusion</p>
  
  <ul>
  <li>Included: (All)</li>
  <li>Excluded: (None)</li>
  <li>Native library location: (None)</li>
  <li>Ignore optional compile problems: (No)</li>
  </ul>
  
  <p>As per other posts, the provider tag is not required.</p>
  
  <p>I tried including each of the provider tags in the correct spot. Neither worked.</p>
  
  <pre><code>&lt;provider&gt;org.apache.openjpa.persistence.PersistenceProviderImpl&lt;/provider&gt;
  &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
  </code></pre>
  
  <p>The following is what I tried with provider tag.</p>
  
  <pre><code>&lt;persistence-unit name="derby" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.apache.openjpa.persistence.PersistenceProviderImpl&lt;/provider&gt;
  
      &lt;class&gt;...&lt;/class&gt;
  
      &lt;properties&gt;
          ...
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;persistence-unit name="derby" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
  
      &lt;class&gt;...&lt;/class&gt;
  
      &lt;properties&gt;
          ...
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>I am currently running it within a JUnit test within the "test" folder, which is in the root directory and also included as a source folder. The JUnit test is failing with the following error.</p>
  
  <pre><code>javax.persistence.PersistenceException: No Persistence provider for EntityManager named derby
  </code></pre>
  
  <p>The following is the line of code that is causing the error.</p>
  
  <pre><code>Persistence.createEntityManagerFactory("derby").createEntityManager();
  </code></pre>