title: Object: entity.ENTITY[ id=null ] is not a known entity type
body: <p>this is a similar post to one I have seen before regarding this exception but I am utterly lost.  I have yet to persist an entity to a database using JPA, although I have read from tables using it no problem.  My setup is Netbeans 7.1 using Glassfish 3.1.1, EclipseLink is my persistence provider.  I have a very simple scenario where I just want to test writing a persons name and age into the database and having the id auto increment.  Its an MySql database with the fields: Id, FirstName and Age.  Heres my code:</p>
  
  <p>Web servlet to take in name and age from html form:</p>
  
  <pre><code>    @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  
      String userPath = request.getServletPath();
  
      if(userPath.equals("/addUser")){
  
          //get request parameters from form
          String name = request.getParameter("name");
          String age = request.getParameter("age");
  
          //set request attributes to be used by forwarded page
          request.setAttribute("name", name);
          request.setAttribute("age", age);
  
          //create manager class to add person to database
          Manager manager = new Manager();
          manager.addPerson(name, age);
  
          userPath = "/result";
      }
  
      // use RequestDispatcher to forward request internally
      String url = "/WEB-INF/view" + userPath + ".jsp";
  
      try {
          request.getRequestDispatcher(url).forward(request, response);
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Manager class that takes in name and age, creates a person object and persists it.</p>
  
  <pre><code>public class Manager {
  
  private static final String PERSISTENCE_UNIT_NAME = "FormPU";
  private static EntityManagerFactory factory;
  
  public Manager() {
  }
  
  public void addPerson(String name, String age) {
  
      factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
      EntityManager em = factory.createEntityManager();
  
      Persons persons = new Persons();
      persons.setName(name);
      persons.setAge(age);
  
      em.getTransaction().begin();
      em.persist(persons);
      em.getTransaction().commit();
      em.close();
  }
  }
  </code></pre>
  
  <p>Persons entity class:</p>
  
  <pre><code>    /**
      *
      * @author esmiala
      */
      @Entity
      @Table(name = "persons")
      @XmlRootElement
      @NamedQueries({
        @NamedQuery(name = "Persons.findAll", query = "SELECT p FROM Persons p"),
        @NamedQuery(name = "Persons.findById", query = "SELECT p FROM Persons p WHERE  
        p.id = :id"),
        @NamedQuery(name = "Persons.findByFirstName", query = "SELECT p FROM Persons p 
        WHERE p.firstName = :firstName"),
        @NamedQuery(name = "Persons.findByAge", query = "SELECT p FROM Persons p WHERE 
        p.age = :age")})
  public class Persons implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @NotNull
  @Column(name = "Id")
  private Integer id;
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 255)
  @Column(name = "FirstName")
  private String firstName;
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 255)
  @Column(name = "Age")
  private String age;
  
  public Persons() {
  }
  
  public Persons(Integer id) {
      this.id = id;
  }
  
  public Persons(Integer id, String firstName, String age) {
      this.id = id;
      this.firstName = firstName;
      this.age = age;
  }
  
  public Integer getId() {
      return id;
  }
  
  public void setId(Integer id) {
      this.id = id;
  }
  
  public String getFirstName() {
      return firstName;
  }
  
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  
  public String getAge() {
      return age;
  }
  
  public void setAge(String age) {
      this.age = age;
  }
  
  @Override
  public int hashCode() {
      int hash = 0;
      hash += (id != null ? id.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 Persons)) {
          return false;
      }
      Persons other = (Persons) object;
      if ((this.id == null &amp;&amp; other.id != null) || (this.id != null &amp;&amp; !this.id.equals(other.id))) {
          return false;
      }
      return true;
  }
  
  @Override
  public String toString() {
      return "entity.Persons[ id=" + id + " ]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Persistence.xml</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="FormPU" transaction-type="JTA"&gt;
       &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
       &lt;jta-data-source&gt;jdbc/form&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&gt;
  </code></pre>
  
  <p>Note:  I have also tried setting exclude-unlisted-classes tag to true and list the class seperately but that didn't work either.</p>
  
  <p>The exception:</p>
  
  <pre><code>    WARNING: StandardWrapperValve[Controller]: PWC1406: Servlet.service() for servlet  
      Controller threw exception
      java.lang.IllegalArgumentException: Object: entity.persons[ id=null ] is not a   
      known entity type.
  atorg.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObject
      ForPersist(UnitOfWorkImpl.java:4141)
  atorg.eclipse.persistence.internal.jpa.EntityManagerImpl.   
      persist(EntityManagerImpl.java:368)
  at manager.Manager.addPerson(Manager.java:36)
  at controller.Controller.doPost(Controller.java:70)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
  </code></pre>
  
  <p>...and so on.  Any help would be greatly appreciated!</p>