title: Can not cast iterator object
body: <p>I wrote this code to cast an iterator object to a predefined object but it fails and it raise a class cast exception:</p>
  
  <pre><code>public ArrayList&lt;Session&gt; getAllSessions() {
  
      ArrayList&lt;Session&gt; sessions = new ArrayList&lt;Session&gt;();
      Query sessionsQuery = null;
      sessionsQuery = this.getSession().getNamedQuery("getAllSessions");
      Iterator trainees = sessionsQuery.list().iterator();
  
      while (trainees.hasNext()) {
          sessions.add((Session) trainees.next());
      }
      return sessions;
  
  }
  
  
  java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to Session
  </code></pre>
  
  <p>Query:</p>
  
  <pre><code>&lt;sql-query name="getAllSessions"&gt;&lt;![CDATA[ select ss.ID,ss.NAME from SESSION_ ss where ss.ISDELETED&lt;&gt;1]]&gt;&lt;/sql-query&gt;
  </code></pre>
  
  <p>what is the problem here?</p>