title: JPA exception: Object: ... is not a known entity type
body: <p>I'm new to JPA and I'm having problems with the autogeneration of primary key values.</p>
  
  <p>I have the following entity:</p>
  
  <pre><code>package jpatest.entities;
  
  import java.io.Serializable;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity
  public class MyEntity implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      private String someProperty;
  
      public String getSomeProperty() {
          return someProperty;
      }
  
      public void setSomeProperty(String someProperty) {
          this.someProperty = someProperty;
      }
  
      public MyEntity() {
      }
  
      public MyEntity(String someProperty) {
          this.someProperty = someProperty;
      }
  
      @Override
      public String toString() {
          return "jpatest.entities.MyEntity[id=" + id + "]";
      }    
  }
  </code></pre>
  
  <p>and the following main method in other class:</p>
  
  <pre><code>public static void main(String[] args) {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPATestPU");
      EntityManager em = emf.createEntityManager();
  
      em.getTransaction().begin();
  
      MyEntity e = new MyEntity("some value");    
      em.persist(e); /* (exception thrown here) */
  
      em.getTransaction().commit();
  
      em.close();
      emf.close();
  }
  </code></pre>
  
  <p>This is my persistence unit:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="1.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_1_0.xsd"&gt;
    &lt;persistence-unit name="JPATestPU" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;oracle.toplink.essentials.PersistenceProvider&lt;/provider&gt;
      &lt;class&gt;jpatest.entities.MyEntity&lt;/class&gt;
      &lt;properties&gt;
        &lt;property name="toplink.jdbc.user" value="..."/&gt;
        &lt;property name="toplink.jdbc.password" value="..."/&gt;
        &lt;property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/jpatest"/&gt;
        &lt;property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
        &lt;property name="toplink.ddl-generation" value="create-tables"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>When I execute the program I get the following exception in the line marked with the proper comment:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Object: jpatest.entities.MyEntity[id=null] is not a known entity type.
          at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3212)
          at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:205)
          at jpatest.Main.main(Main.java:...)
  </code></pre>
  
  <p><strong>What am I missing?</strong></p>