title: Unknown entity class error message even though the entity is marked with @Entity annotation
body: <p>I am building REST web app using Netbean6.9.1 and JPA EclipseLink.</p>
  
  <p>The issue I'm facing is even though my entity class MasatoTable is marked with Entity annotation, I get error:</p>
  
  <pre><code>    (java.lang.IllegalArgumentException: Unknown entity bean class:
       class entity.MasatoTable, please verify that this class
   has been marked with the @Entity annotation.)
  </code></pre>
  
  <p>The thing is <strong>when I restart the GlassFish3 server from NetbeanIDE, it works for a while and somehow at some point, the error start showing up.</strong> I used to use Toplink Essential and had no issue but I've changed to EclipseLink and re-defiend persistence.xml (shown below) and this problem started. But I don't see any code error that I can think of..</p>
  
  <p><strong>MasatoTable.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "MasatoTable")
  public class MasatoTable implements Serializable {
  ...continue code...
  </code></pre>
  
  <p><strong>persistence.xml</strong></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="kojoPU"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;non-jta-data-source&gt;jdbc/koga_kojo&lt;/non-jta-data-source&gt;
      &lt;class&gt;entity.MasatoTable&lt;/class&gt;
      &lt;properties&gt;
        &lt;property name="eclipselink.logging.logger" value="JavaLogger"/&gt;
        &lt;property name="eclipselink.logging.level.sql" value="FINEST"/&gt;
        &lt;property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://KOGADBSERVER;databaseName=MasatoDB"/&gt;
        &lt;property name="javax.persistence.jdbc.password" value="foobar"/&gt;
        &lt;property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/&gt;
        &lt;property name="javax.persistence.jdbc.user" value="koga"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Looks like same issue but that ticket's solution is to rollback to Toplink from Eclipselink. Has anyone solve the issue without rolling back to toplink?</p>
  
  <p><a href="https://stackoverflow.com/questions/4381541/unknown-entity-bean-class-after-hot-deploy-netbeans-6-9-glassfish-2-1-eclips">Unknown entity bean class after hot deploy: netbeans 6.9 + glassfish 2.1 + eclipselink jpa 2.0</a></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As far as my research goes in terms of this case, look like the bug has been addressed and fixed? </p>
  
  <p><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=288141" rel="nofollow noreferrer">https://bugs.eclipse.org/bugs/show_bug.cgi?id=288141</a></p>
  
  <p>I'm not knowledgeable enough to understand the whole thing but there are few facts I found:</p>
  
  <p>Netbean6.9.1 provides EclipseLink 2.0.1 whereas newest version is 2.2.0</p>
  
  <p>I downloaded newest version and put them into the lib dir then re-deployed but no luck, the issue still persists. Not sure if I did things in wrong way. </p>
  
  <p><strong>UPDATE after James's comment</strong></p>
  
  <p>Below is the class I use to create singleton EntityManagerFactory and how it is being used.</p>
  
  <pre><code>package common;
  
  import java.util.Date;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  public class EmProvider {
  
      private static final String DB_PU = "kojoPU"; //工場DB
  
      public static final boolean DEBUG = false;
  
      private static final EmProvider singleton = new EmProvider();
  
      private EntityManagerFactory emf;
  
      private EmProvider() {}
  
      public static EmProvider getInstance() {
          return singleton;
      }
  
  
      public EntityManagerFactory getEntityManagerFactory() {
          if(emf == null) {
              emf = Persistence.createEntityManagerFactory(DB_PU);
          }
          if(DEBUG) {
              System.out.println("factory created on: " + new Date());
          }
          return emf;
      }
  
      public void closeEmf() {
          if(emf.isOpen() || emf != null) {
              emf.close();
          }
          emf = null;
          if(DEBUG) {
              System.out.println("EMF closed at: " + new Date());
          }
      }
  
  }//end class
  </code></pre>
  
  <p><strong>How it is used:</strong></p>
  
  <pre><code>EntityManager em = null;
     Object out = null;
     try {
         em = EmProvider.getInstance().getEntityManagerFactory().createEntityManager();
         Query query = em.createNativeQuery(sql);
  
         ....some code here
     }
     finally {
         if(em != null) {
             em.close();
         }
     }
  </code></pre>
  
  <p>By looking at my code, I think... <strong>I'm not closing EntityManagerFactory</strong> (i'm closing EntityManager in finally though)</p>
  
  <p>I also I found the <code>"unknown entity bean class"</code> error in topic shows up for sure with following action.</p>
  
  <ol>
  <li><p>Deploy web app through Netbean (This will open the browser)</p></li>
  <li><p>Change some code in Netbean IDE and save it. Then Netbean will auto-re-deploy as soon as you press the save button (is this called "hot deploy" ???)</p></li>
  <li><p>Go back to browser and take some action like add some data which involves EntityManager.</p></li>
  </ol>
  
  <p>Looks like the error occurs because I'm not closing entity manager factory when hot-deploy? I have to investigate.</p>