title: JPA returns empty objects
body: <p>My User model</p>
  
  <pre><code>@Entity
  @Table(name="users")
  data class User(
          @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
          val id: Long = -1,
          @Column(unique=true)
          val username: String) : Serializable
  </code></pre>
  
  <p>Two records in the database</p>
  
  <p><a href="https://i.stack.imgur.com/I5YXA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I5YXA.png" alt="database"></a></p>
  
  <p>The query is fine.</p>
  
  <blockquote>
    <p>[2018-02-23T14:32:07.066+0100] [Payara 4.1] [FINE] []
    [org.eclipse.persistence.session./file:/Users/youri/Downloads/payara41/glassfish/domains/domain1/applications/Kwetter-1.0-SNAPSHOT/WEB-INF/classes/_kwetter.sql]
    [tid: _ThreadID=28 _ThreadName=http-thread-pool::http-listener-1(4)]
    [timeMillis: 1519392727066] [levelValue: 500] [[   <strong>SELECT ID, USERNAME
    FROM users</strong>]]</p>
  </blockquote>
  
  <p>But it outputs two empty objects, instead of two <strong>User</strong> objects</p>
  
  <pre><code>[{},{}]
  </code></pre>
  
  <p>Abstract Dao where I use the Entity Manager</p>
  
  <pre><code>@Stateless
  abstract class Abstract&lt;T : Serializable&gt; {
      @PersistenceContext
      private lateinit var entityManager: EntityManager
  
      abstract fun getEntityClass(): Class&lt;T&gt;
  
      open fun find(id: Long): T {
          return entityManager.find(getEntityClass(), id)
      }
  
      // this returns the weird two empty objects
      open fun all(): List&lt;T&gt; {
          val builder = entityManager.criteriaBuilder
          val c = builder.createQuery(getEntityClass())
          c.from(getEntityClass())
          val query = entityManager.createQuery(c)
  
          return query.resultList
      }
  }
  </code></pre>