title: How to fetch hibernate query result as associative array of list or hashmap
body: <p>I am developing an application in struts 2 and hibernate 3.</p>
  
  <p>I have 3 tables</p>
  
  <ol>
  <li>Inspection</li>
  <li>InspectionMission</li>
  <li>Timeline</li>
  </ol>
  
  <p><code>Inspection</code> is associated with <code>InspectionMission</code> and <code>InspectionMission</code> is associated with <code>Timeline</code>.</p>
  
  <p>Now I have following problem. I have written following query in HQL</p>
  
  <pre><code>public List getQuartewiseInspectionList(){
  
     Session session = HibernateUtil.getSessionFactory().getCurrentSession();
  
     Query q = session.createQuery(
                  "select count(i.inspectionId) as tot_inspections,t.year,t.quarter" +
                  " From Inspection as i " +
                  " inner join i.inspectionMission as im inner join im.timeline as t" +
                  " GROUP by t.year,t.quarter");
  
     return q.list();
  
  }
  </code></pre>
  
  <p>I want to fetch result as following</p>
  
  <pre><code>result[0][tot_inspections] = "6"
  result[0][year] = "2009";
  result[0][quarter] = "Q2";
  
  result[1][tot_inspections] = "3"
  result[1][year] = "2009";
  result[1][quarter] = "Q3";
  </code></pre>
  
  <p>and so on so that I can display it in jsp struts as follows:</p>
  
  <p>In JSP I have written following code</p>
  
  <pre><code>&lt;table border="1"&gt;
  
     &lt;s:iterator value="result" status="status"&gt;
         &lt;tr class="&lt;s:if test="#status.even"&gt;even&lt;/s:if&gt;&lt;s:else&gt;odd&lt;/s:else&gt;"&gt;
               &lt;td class="nowrap"&gt;&lt;s:property value="tot_inspections" /&gt;&lt;/td&gt;
               &lt;td class="nowrap"&gt;&lt;s:property value="year" /&gt;&lt;/td&gt;
               &lt;td class="nowrap"&gt;&lt;s:property value="quarter" /&gt;&lt;/td&gt;
         &lt;/tr&gt;         
      &lt;/s:iterator&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Can anyone here help me?</p>