title: hibernate: how to select all rows in a table
body: <p>I try to do something like <code>Select * from LogEntry</code> with Hibernate.
  insert works fine:</p>
  
  <pre><code>import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  [...]
  protected EntityManager manager;
  
  protected final String tableName = "LogEntry";
  
  public DatabaseImpl(DB_TYPE db) {
      this.db = db;
      if (entityManagerFactory != null &amp;&amp; entityManagerFactory.isOpen()) {
          entityManagerFactory.close();
      }
      entityManagerFactory = Persistence.createEntityManagerFactory(db.getPersUnit());
      manager = entityManagerFactory.createEntityManager();
  }
  public void insert(LogEntry entry) {
  
      manager.getTransaction().begin();
      manager.persist(entry);
      manager.getTransaction().commit();
  }
  </code></pre>
  
  <p>But when I try to get the inserted values using this method:
      public LogEntryList getAll() {</p>
  
  <pre><code>    manager.getTransaction().begin();
  
      Query query = manager.createNativeQuery("SELECT * FROM " + tableName + ";");
      ArrayList&lt;LogEntry&gt; entries = (ArrayList&lt;LogEntry&gt;) query.getResultList();
      manager.getTransaction().commit();
  
      return new LogEntryList(entries);
  }
  </code></pre>
  
  <p>I always get the Exception: 
  <code>java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to de.motza.entities.LogEntry</code></p>
  
  <p>I know the problem is the casting of the Query result to the object, but I can't find anywhere how to cast the objects properly, or how to get more than one row from the table.</p>
  
  <p>does anybody have any advice?
  If requested, I can post my persistence.xml and more code</p>