title: JPA query.getResultList() returning wrong objects?
body: <p>I am doing the query below to test if JPA is retrieving the expected results from the database. </p>
  
  <p>I can't understand why <code>row instanceof Ativo</code> is returning false. <code>row.getClass()</code> returns <code>br.meuspila.entity.Ativo</code>, and the printed object is <code>br.meuspila.entity.Ativo[ id=1 ]</code>. The imports of the class are ok, and there is not other class named Ativo inside the same package.</p>
  
  <pre><code>// OUTPUT:
  INFO:   br.meuspila.entity.Ativo[ id=1 ]  // row
  INFO:   false  // row instanceof Ativo?
  INFO:   class br.meuspila.entity.Ativo  // row.getClass()
  </code></pre>
  
  <hr>
  
  <p>MyMB class:</p>
  
  <pre><code>package br.meuspila.mb;
  
  import br.meuspila.database.JpaUtil;
  import br.meuspila.entity.Ativo;
  import java.util.List;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.persistence.EntityManager;
  import javax.persistence.EntityTransaction;
  import javax.persistence.Query;
  
  @ManagedBean
  @SessionScoped
  public class MyMB {
  
      public String teste = "testando, 123";
  
      /**
       * Creates a new instance of ManagedBean
       */
      public MyMB() {
      }
  
      public String getTeste() {
          return teste;
      }
  
      public void setTeste(String teste) {
          this.teste = teste;
      }
  
      public void actionTeste() {
          EntityManager em = JpaUtil.getInstance().createEntityManager();
  
          try {
              EntityTransaction t = em.getTransaction();
              t.begin();
  
              Query query = em.createQuery("select x from Ativo x");
              List result = query.getResultList();
  
              for (Object row : result) {
                  System.out.println(row);
                  System.out.println(row instanceof Ativo);
                  System.out.println(row.getClass());
              }
  
              t.commit();
  
          } finally {
              em.close();
          }        
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>JpaUtil class:</p>
  
  <pre><code>package br.meuspila.database;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  public final class JpaUtil {
  
      private JpaUtil() {
      }
  
      public static JpaUtil getInstance() {
          return JpaUtilHolder.INSTANCE;
      }
  
      private static class JpaUtilHolder {
          private static final JpaUtil INSTANCE = new JpaUtil();
          private static final EntityManagerFactory EMF = Persistence.createEntityManagerFactory("MeusPila3_WebPU");
      }
  
      public EntityManager createEntityManager() {
          return JpaUtilHolder.EMF.createEntityManager();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>persistence.xml:</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="MeusPila3_WebPU" transaction-type="JTA"&gt;
      &lt;jta-data-source&gt;jdbc/meuspiladb&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <hr>
  
  <p>My project configuration (Web Project):</p>
  
  <pre><code>JPA 2.1 - EclipseLink-2.5.0.v20130507-rNA
  GlassFish Server 4
  
  NetBeans IDE 7.3.1 (Build 201306052037)
  Java: 1.7.0_25; Java HotSpot(TM) 64-Bit Server VM 23.25-b01
  Runtime: Java(TM) SE Runtime Environment 1.7.0_25-b17
  System: Windows 7 version 6.1 running on amd64; Cp1252; pt_BR (nb)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/RhriA.png" alt="Project view on NetBeans 7.3.1"></p>
  
  <p>Note: <code>JpaUtil</code> class was inside <code>br.meuspila.database</code> package.</p>