title: no persistence provider for EntityManager named persistence.xml
body: <p><strong>This is not a duplicate as the tag above purports.  This question has not yet been answered.</strong>  </p>
  
  <p>I am trying to set up <a href="http://confluence.highsource.org/display/HJ3/Purchase+Order+Tutorial" rel="nofollow noreferrer">this tutorial</a> to get <code>hyperjaxb</code> to work in an eclipse project.  How can I get it to see a persistence provider?  <code>hbm2ddl</code> has NOT created the table structure in the database yet.  Is that why the app is not seeing a persistence provider?  Or is it because the contents of <code>persistence.xml</code> in <code>target/generated-sources</code> are not accessible from the <code>src/main/java</code> directory in which my <code>TestFunctions.java</code> is trying to call it?  Here are the specifics... This line of code:  </p>
  
  <pre><code>entityManagerFactory = Persistence.createEntityManagerFactory("persistence.xml", persistenceProperties);  
  </code></pre>
  
  <p>Is throwing this error:  </p>
  
  <pre><code>Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named persistence.xml
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      at maintest.TestFunctions.setUpPersistence(TestFunctions.java:119)
      at maintest.Main.main(Main.java:10)
  </code></pre>
  
  <p>The code throwing the error is in this method:  </p>
  
  <pre><code>public void setUpPersistence(){
      final Properties persistenceProperties = new Properties();
      InputStream is = null;
      try {
          Class&lt;? extends TestFunctions&gt; c = getClass();
          ClassLoader cl = c.getClassLoader();
          is = cl.getResourceAsStream("persistence.properties");
          persistenceProperties.load(is);
      }catch (IOException i) {i.printStackTrace();}
      finally {if (is != null) {try {is.close();} catch (IOException ignored) {}}}
      entityManagerFactory = Persistence.createEntityManagerFactory("persistence.xml", persistenceProperties);
  }  
  </code></pre>
  
  <p><code>persistence.xml</code>:  </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
  http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
          &lt;persistence-unit name="org.jvnet.hyperjaxb3.ejb.tests.po"&gt;
              &lt;class&gt;org.jvnet.hyperjaxb3.ejb.tests.po.Items&lt;/class&gt;
              &lt;class&gt;org.jvnet.hyperjaxb3.ejb.tests.po.Items$Item&lt;/class&gt;
              &lt;class&gt;org.jvnet.hyperjaxb3.ejb.tests.po.PurchaseOrderType&lt;/class&gt;
              &lt;class&gt;org.jvnet.hyperjaxb3.ejb.tests.po.USAddress&lt;/class&gt;
          &lt;/persistence-unit&gt;
      &lt;/persistence&gt;
  </code></pre>
  
  <p><code>persistence.properties</code> is:  </p>
  
  <pre><code>hibernate.dialect=org.hibernate.dialect.MySQLDialect
  hibernate.connection.driver_class=com.mysql.jdbc.Driver
  hibernate.connection.username=someusername
  hibernate.connection.password=somepassword
  hibernate.connection.url=jdbc:mysql://localhost/somedatabasename
  hibernate.hbm2ddl.auto=create-drop
  hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
  hibernate.jdbc.batch_size=0
  </code></pre>
  
  <p>The directory structure for the eclipse project is:  </p>
  
  <p><img src="https://s1.postimg.org/72dvc270v/dirstruct.jpg">  </p>
  
  <hr>
  
  <h2>**EDIT:  **</h2>
  
  <p>Just for kicks, I moved the <code>META-INF</code> folder to the same level as the calling class, but I get the same error.  Here are two new screen shots showing locations of persistence.xml in which the error is still thrown:  </p>
  
  <p>
  
  <img src="https://s15.postimg.org/5ritdg7ff/dirstruct2.jpg">
  <img src="https://s28.postimg.org/pqxbf7w1p/dirstruct3.jpg">
  
  
  
  <hr>
  
  <h2><strong>SECOND EDIT:</strong></h2>
  
  <p>I added <code>Class c = Class.forName("org.eclipse.persistence.jpa.PersistenceProvider");</code> at line 116 of <code>TestFunctions.java</code>, which triggers the following error when I right click on <code>Main.java</code> and do <code>Run As..Java Application</code>:  </p>
  
  <pre><code>Exception in thread "main" java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at maintest.TestFunctions.setUpPersistence(TestFunctions.java:116)
      at maintest.Main.main(Main.java:10)  
  </code></pre>
  
  <p>Here is the new <code>TestFunctions.setUpPersistence()</code> method:  </p>
  
  <pre><code>public void setUpPersistence() throws ClassNotFoundException{
      final Properties persistenceProperties = new Properties();
      InputStream is = null;
      try {
          Class&lt;? extends TestFunctions&gt; c = getClass();
          ClassLoader cl = c.getClassLoader();
          is = cl.getResourceAsStream("persistence.properties");
          persistenceProperties.load(is);
      }catch (IOException i) {i.printStackTrace();}
      finally {if (is != null) {try {is.close();} catch (IOException ignored) {}}}//org.jvnet.hyperjaxb3.ejb.tests.po
      Class c = Class.forName("org.eclipse.persistence.jpa.PersistenceProvider");
      entityManagerFactory = Persistence.createEntityManagerFactory(/*"org.jvnet.hyperjaxb3.ejb.tests.po"*//*"persistence.xml"*/"org.jvnet.hyperjaxb3.ejb.tests.po", persistenceProperties);
  }
  </code></pre>
  
  <p>When I replace <code>Class c = Class.forName("org.eclipse.persistence.jpa.PersistenceProvider");</code> with <code>Class c = Class.forName("org.hibernate.ejb.HibernatePersistence");</code>, I get a similar error.  However, <code>Class c = Class.forName("javax.persistence.spi.PersistenceProvider");</code> does not throw any error, so the program continues until the same <code>javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jvnet.hyperjaxb3.ejb.tests.po</code> error gets thrown further downstream.</p>
  
  <p><strong>Does this tell us more about the cause of the error?</strong>  Also, <code>hyperjaxb</code> creates a <code>persistence.xml</code> and places it in the target folder.  This error occurred when <code>persistence.xml</code> was in that location, and has persisted when I move <code>persistence.xml</code> as shown above. <strong>Is <code>hyperjaxb</code> causing this problem by not playing nicely with eclipse?</strong></p>