我正在Struts 2和Hibernate 3中开发应用程序。
我有3张桌子
Inspection与关联并InspectionMission与InspectionMission关联Timeline。
Inspection
InspectionMission
Timeline
现在我有以下问题。我已经在HQL中编写了以下查询
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(); }
我想获取结果如下
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";
等等,这样我就可以在jsp struts中显示它,如下所示:
在JSP中,我编写了以下代码
<table border="1"> <s:iterator value="result" status="status"> <tr class="<s:if test="#status.even">even</s:if><s:else>odd</s:else>"> <td class="nowrap"><s:property value="tot_inspections" /></td> <td class="nowrap"><s:property value="year" /></td> <td class="nowrap"><s:property value="quarter" /></td> </tr> </s:iterator> </table>
这里有人可以帮助我吗?
您必须使用“新地图”语法(Hibernate参考段落14.6)
select new map(count(i.inspectionId) as tot_inspections, t.year as year, t.quarter as quarter) from ...
其余查询是相同的。这将返回一个地图列表,其中的键是“列”的别名。