日期:2014-05-20  浏览次数:20868 次

getHibernateTemplate()多表连接查询问题
难道getHibernateTemplate()不支持多表连接查询吗??
select top 1 t.topic,u.username,t.createtime from Topic t inner join Users u on t.usersid=u.id order by t.createtime
这么写怎么总报错呢..
错误信息
org.apache.jasper.JasperException: javax.servlet.ServletException: org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: 1 near line 1, column 12 [select top 1 t.topic,u.username,t.createtime from com.godlike.model.Topic t inner join Users u on t.usersid=u.id order by t.createtime]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 1 near line 1, column 12 [select top 1 t.topic,u.username,t.createtime from com.godlike.model.Topic t inner join Users u on t.usersid=u.id order by t.createtime]
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


------解决方案--------------------
HIBERNATE支持多表连接查询,但是不识别on关键字,你要在HIBERNATE配置文件中配置好对象的关系,如many-to-one,one-to-many.
那么on 和后边的关联条件就不用写了。
------解决方案--------------------
hibernate不支持top 查询
getHibernateTemplate().setMaxResult....
getHibernateTemplate().find(hql);

------解决方案--------------------
探讨
hibernate不支持top 查询
getHibernateTemplate().setMaxResult....
getHibernateTemplate().find(hql);

------解决方案--------------------
这个不是多表连接的问题,是分页的问题