title: Hibernate/JPA : IllegalArgumentException: Not an entity
body: <p>I try to run a basic application with hibernate and jpa, but now I'm stuck on this exception when running app...Here's the code and erro below:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Not an entity: class pka.EclipseJPAExample.domain.Employee
  at org.hibernate.ejb.metamodel.MetamodelImpl.entity(MetamodelImpl.java:158)
  at org.hibernate.ejb.criteria.QueryStructure.from(QueryStructure.java:136)
  at org.hibernate.ejb.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:177)
  at pka.EclipseJPAExample.jpa.JpaTest.createEmployees(JpaTest.java:47)
  at pka.EclipseJPAExample.jpa.JpaTest.main(JpaTest.java:33)
  </code></pre>
  
  <p>JpaTest.java: </p>
  
  <pre><code>public class JpaTest {
  private EntityManager manager;
  public JpaTest(EntityManager manager) {
      this.manager = manager;
  }
  /**
   * @param args
   */
  public static void main(String[] args) {
      EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
      EntityManager manager = factory.createEntityManager();
      JpaTest test = new JpaTest(manager);
  
      EntityTransaction tx = manager.getTransaction();
      tx.begin();
      try {
          test.createEmployees();
      } catch (Exception e) {
          e.printStackTrace();
      }
      tx.commit();
  
      test.listEmployees();
  
      System.out.println(".. done");
  }
  
  private void createEmployees() {
      CriteriaBuilder builder = manager.getCriteriaBuilder();
      CriteriaQuery&lt;Employee&gt; query = builder.createQuery(Employee.class);
      query.from(Employee.class);
  
      int numOfEmployees = manager.createQuery(query).getResultList().size();
      if (numOfEmployees == 0) {
          Department department = new Department("java");
          manager.persist(department);
  
          manager.persist(new Employee("Jakab Gipsz",department));
          manager.persist(new Employee("Captain Nemo",department));
  
      }
  }
  
  
  private void listEmployees() {
      CriteriaBuilder builder = manager.getCriteriaBuilder();
      CriteriaQuery&lt;Employee&gt; query = builder.createQuery(Employee.class);
      query.from(Employee.class);
      List&lt;Employee&gt; resultList = manager.createQuery(query).getResultList();
  
      for (Employee next : resultList) {
          System.out.println("next employee: " + next);
      }
  }
  }
  </code></pre>
  
  <p>and persistence.xml:</p>
  
  <pre><code>....&lt;persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
  
          &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/testowa" /&gt;
          &lt;property name="javax.persistence.jdbc.user" value="root" /&gt;
          &lt;property name="javax.persistence.jdbc.password" value="enchantsql" /&gt;
  
          &lt;property name="hbm2ddl.auto" value="create" /&gt;
  
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt;        
      &lt;/properties&gt;
  
  &lt;/persistence-unit&gt;....
  </code></pre>
  
  <p>Could you point where is the problem?</p>
  
  <p><strong>EDIT:</strong>
  I forgot to paste Employee class...so here it is below:</p>
  
  <pre><code>@Entity
  @Table(name="Employee")
  public class Employee {
  @Id
  @GeneratedValue
  private Long id;
  
  private String name;
  
  @ManyToOne
  private Department department;
  
  public Employee() {}
  
  public Employee(String name, Department department) {
      this.name = name;
      this.department = department;
  }
  
  
  public Employee(String name) {
      this.name = name;
  }
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public Department getDepartment() {
      return department;
  }
  
  public void setDepartment(Department department) {
      this.department = department;
  }
  
  @Override
  public String toString() {
      return "Employee [id=" + id + ", name=" + name + ", department="
              + department.getName() + "]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>As you can see it is mapped.</p>