以下是我在开发ssh中出现的异常,请各位帮忙解决一下
org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: 5 near line 1, column 12 [select top 5 * from com.no9.entity.Goods order by PutTime desc]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 5 near line 1, column 12 [select top 5 * from com.no9.entity.Goods order by PutTime desc]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:639)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:377)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:840)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:832)
at com.no9.dao.impl.GoodsDAO.findTopByTime(GoodsDAO.java:194)
at com.no9.biz.impl.GoodsBizImpl.findTopByPubTime(GoodsBizImpl.java:39)
at org.apache.jsp.right_jsp._jspService(right_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
at org.apache.struts2.components.Include.include(Include.java:254)
at org.apache.struts2.components.Include.end(Include.java:166)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.index_jsp._jspx_meth_s_005finclude_005f3(index_jsp.java:173)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:82)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
相关代码如下----DAO层
//通过时间查询最新发布的产品
public List findTopByTime(){
log.debug("finding top By Time Goods instances");
try {
String queryString = "select top 5 * from Goods order by PutTime desc";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
BIZ层
//查询最新发布 5条记录
public List findTopByPubTime(){
List listTopTime = gooddao.findTopByTime();
if(listTopTime != null && listTopTime.size() > 0){
System.out.println(listTopTime.size());
return listTopTime;
}else{
return null;
}
}
页面代码为:
<%
//查询最新发布---
GoodsBizImpl topPubTime = (GoodsBizImpl)SpringBeanUtil.getInstance().getBean("GoodsBiz");
List listTopTime = topPubTime.findTopByPubTime();
session.setAttribute("topTime",listTopTime);//将手机信息保存到session中
%>
<div class="frameBorder" style="width:150px">
<s:iterator id="topTime" value="#session.topTime" status="stuts">
<div>
<a href="#"><img src="images/products/<s:property value="images" />"/></a>
<s:property value="goodName" />
</div>
</s:iterator>
</div>
现在一时找不到原因,望各位给予解决,谢谢
[b]问题补充:[/b]
在DAO层的sql语句在sql server 2005 中是可以执行的,在HQL中就有点问题啦,关键是怎么改。本人刚学SSH不久,对有些东西还希望各位多提一些建议
[b]问题补充:[/b]
我用的是Spring + Struts2 + Hibernate3.2架构的,所以
String hql = "from Goods order by PutTime desc";
List results = session.createQuery(hql).setMaxResults(5).list();
用session好像不行啊