title: hibernate - iterating query
body: <p>I have two testing tables associated by foreign key</p>
  
  <ul>
  <li>table <code>School</code> (with fk on <code>student_id</code>) </li>
  <li>table <code>Students</code> (with pk on <code>id</code>)</li>
  <li>FK: <code>school.student_id -&gt; students.id</code></li>
  </ul>
  
  <p>How can I get students name using this query?</p>
  
  <pre><code>Session session = DaoSF.getSessionFactory().openSession();
  String query = "";
  Query criteria;
  
  query = "from School s " +
          "inner join s.student st " +
          "where s.student_id = st.id";
  criteria = session.createQuery(query);
  </code></pre>
  
  <p>When I try to iterate data:</p>
  
  <pre><code>for(Iterator&lt;?&gt; iter = criteria.iterate(); iter.hasNext();)
  {
    Object item = (Object)iter.next();
    System.out.println(((School) item).getStudent().getId());
  }
  </code></pre>
  
  <p>it reports: </p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to table.School
  </code></pre>
  
  <p>but mapping is working, because when i've changed the last row to </p>
  
  <p><code>System.out.println(item.toString());</code></p>
  
  <p>I've got all the data but like that:</p>
  
  <pre><code>[Ljava.lang.Object;@1d2300e
  [Ljava.lang.Object;@51207c
  [Ljava.lang.Object;@2bd615
  ...
  </code></pre>