title: How to setup JPA project with hibernate
body: <p>I really need your help this time. I'm trying to build a very simple jpa example with hibernate and I just can't figure out why it's not working.</p>
  
  <p>here is the code: 
  main</p>
  
  <pre><code>package hi;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  public class pl {
  public static void main(String[] args) {
  
  
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("ahhhhhPU");
      EntityManager em = emf.createEntityManager();
      Moon m = new Moon(56);
  
      em.getTransaction().begin();
  
      try{
          em.persist(m);
          em.getTransaction().commit();
      }catch (Exception e){
          System.out.println("ERROR!!");
          e.printStackTrace();
          em.getTransaction().rollback();
      }finally {
          em.close();
      }
  
      System.out.println("done&amp;DONE!!!");
  }
  }
  </code></pre>
  
  <p>the entity: (automatically made)</p>
  
  <pre><code>package hi;
  
  import java.io.Serializable;
  import javax.persistence.Basic;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.NamedQueries;
  import javax.persistence.NamedQuery;
  import javax.persistence.Table;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  import javax.xml.bind.annotation.XmlRootElement;
  
  @Entity
  @Table(name = "moon", catalog = "test", schema = "")
  @XmlRootElement
  @NamedQueries({
  @NamedQuery(name = "Moon.findAll", query = "SELECT m FROM Moon m"),
  @NamedQuery(name = "Moon.findByNum", query = "SELECT m FROM Moon m WHERE m.num = :num"),
  @NamedQuery(name = "Moon.findByName", query = "SELECT m FROM Moon m WHERE m.name = :name")})
  public class Moon implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @NotNull
  @Column(name = "num")
  private Integer num;
  @Size(max = 50)
  @Column(name = "Name")
  private String name;
  
  public Moon() {
  }
  
  public Moon(Integer num) {
      this.num = num;
  }
  
  public Integer getNum() {
      return num;
  }
  
  public void setNum(Integer num) {
      this.num = num;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  @Override
  public int hashCode() {
      int hash = 0;
      hash += (num != null ? num.hashCode() : 0);
      return hash;
  }
  
  @Override
  public boolean equals(Object object) {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Moon)) {
          return false;
      }
      Moon other = (Moon) object;
      if ((this.num == null &amp;&amp; other.num != null) || (this.num != null &amp;&amp; !this.num.equals(other.num))) {
          return false;
      }
      return true;
  }
  
  @Override
  public String toString() {
      return "hi.Moon[ num=" + num + " ]";
  }
  
  }
  </code></pre>
  
  <p>and the persistence:</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="ahhhhhPU" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
      &lt;jta-data-source&gt;test&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties/&gt;
    &lt;/persistence-unit&gt;
    &lt;persistence-unit name="ahhhhhPU2" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
      &lt;jta-data-source&gt;test&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
        &lt;property name="javax.persistence.schema-generation.database.action" value="create"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I'm getting this error: (on my EntityManagerFactory)</p>
  
  <pre><code>debug:
  Apr 20, 2015 12:28:50 PM org.hibernate.ejb.HibernatePersistence logDeprecation
  WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
  Apr 20, 2015 12:28:50 PM org.hibernate.ejb.HibernatePersistence logDeprecation
  WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
  Apr 20, 2015 12:28:50 PM org.hibernate.ejb.HibernatePersistence logDeprecation
  WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
  Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/jandex/IndexView
      at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
      at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:129)
      at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:93)
      at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:86)
      at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:101)
      at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:67)
      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
      at hi.pl.main(pl.java:20)
  Caused by: java.lang.ClassNotFoundException: org.jboss.jandex.IndexView
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 10 more
  Java Result: 1
  BUILD SUCCESSFUL (total time: 1 second)
  </code></pre>
  
  <p>can someone help?
  thanks...</p>