title: Can't configure JPA with Intellij
body: <p>Im trying to configure a simple JPA project and I'm very stuck.</p>
  
  <p>I have a working dataSource (MySQL) &amp; GlassFish with multiple tables.</p>
  
  <p>I did the following steps (all of the files generated by Intellij):</p>
  
  <ol>
  <li><p>Create new project with Java EE Persistance with Hibernate Provider.</p></li>
  <li><p>Import DB that has a Student table. </p></li>
  <li><p>Generate Entity classes with Intellij IDE.</p></li>
  <li><p>Import Hibernate-entitymanager library from Maven.</p></li>
  <li><p>Import MySQL connector.</p></li>
  <li><p>Try to run a simple JPA program to create new row but I get an exeption : </p>
  
  <p>No Persistence provider for EntityManager named persistenceUnit</p></li>
  </ol>
  
  <p>What can be the problem? I tried almost every tutorial and every question here but with no success!</p>
  
  <p>Please Help me!</p>
  
  <p>(sometimes the Hibernate in the persistance provider is colored red)</p>
  
  <p>persistance:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"&gt;
  
      &lt;persistence-unit name="NewPersistenceUnit"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;class&gt;modules.CourseEntity&lt;/class&gt;
          &lt;class&gt;modules.StuCouEntity&lt;/class&gt;
          &lt;class&gt;modules.StudentsEntity&lt;/class&gt;
          &lt;class&gt;modules.TeacherEntity&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306"/&gt;
              &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;
              &lt;property name="hibernate.connection.username" value="root"/&gt;
              &lt;property name="hibernate.connection.password" value="123456"/&gt;
              &lt;property name="hibernate.archive.autodetection" value="class"/&gt;
              &lt;property name="hibernate.show_sql" value="true"/&gt;
              &lt;property name="hibernate.format_sql" value="true"/&gt;
              &lt;property name="hbm2ddl.auto" value="update"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Main.java:</p>
  
  <pre><code>import modules.StudentsEntity;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  public class MainClass
  {
      public static void main(String[] args)
      {
          StudentsEntity stu = new StudentsEntity();
          stu.setName("David");
  
          EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
          EntityManager em = emf.createEntityManager();
  
          em.getTransaction().begin();
          try
          {
              em.persist(stu);
              em.getTransaction().commit();
          }
          catch (Exception ex)
          {
              System.out.println(ex.getMessage());
              ex.printStackTrace();
              em.getTransaction().rollback();
          }
          finally
          {
              em.close();
          }
  
  
  
      }
  }
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>June 16, 2017 5:47:07 PM org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
  June 16, 2017 5:47:07 PM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.1.5.Final}
  June 16, 2017 5:47:07 PM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  June 16, 2017 5:47:07 PM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named persistenceUnit
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      at MainClass.main(MainClass.java:17)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
  </code></pre>