org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query 问题的解决

ERROR [http-80-Processor25] UseraccesslogDAOHibernate.doInHibernate(120) | query sql catch excepti
on:
org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the qu
ery. [select distinct Wapcontent.title,count(*) from useraccesslog,wapcontent where Useraccesslog.contentId=Wa
pcontent.contentId and Useraccesslog.createdate >='2008-08-07 15:11:49' and Useraccesslog.createdate <='2008-0
8-07 18:11:49' group by Useraccesslog.contentId order by count(*) desc]
 at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:169)
 at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:140)
 at com.zrrt.wapportal.dao.hibernate.UseraccesslogDAOHibernate$1.doInHibernate(UseraccesslogDAOHibernate.java:
118)
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:329)
 at com.zrrt.wapportal.dao.hibernate.UseraccesslogDAOHibernate.getUseraccesslogsByCpAContent(UseraccesslogDAOH
ibernate.java:113)
 at com.zrrt.wapportal.service.impl.UseraccesslogManagerImpl.getUseraccesslogsByCpAContent(UseraccesslogManage
rImpl.java:69)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.ja
va:155)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
 at $Proxy13.getUseraccesslogsByCpAContent(Unknown Source)
 at com.zrrt.wapportal.webapp.action.GameProviderAction.getGameProvidersAccess(GameProviderAction.java:3140)
 at com.zrrt.wapportal.webapp.action.GameProviderAction.findGameProviderAccess(GameProviderAction.java:2984)
 at com.zrrt.wapportal.webapp.action.GameProviderAction.findGameProviderCpAccess(GameProviderAction.java:2801)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:302)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:170)
 at com.zrrt.wapportal.webapp.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.ja
va:56)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:115)
 at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:229)
 at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:199)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
 at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.zrrt.wapportal.webapp.filter.GZIPFilter.doFilter(GZIPFilter.java:51)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.zrrt.wapportal.webapp.filter.ActionFilter.doFilter(ActionFilter.java:119)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilte
r.java:174)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
 at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:84)
 at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:182)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java
:153)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.wrapper.ContextHolderAwareRequestFilter.doFilter(ContextHolderAwareRequestFilter.java
:50)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFil
ter.java:226)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
 at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
 at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:482)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
 at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.j
ava:665)
 at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
 at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
 at java.lang.Thread.run(Thread.java:595)
org.springframework.orm.hibernate3.HibernateQueryException: addEntity() or addScalar() must be called on a sql
 query before executing the query. [select distinct Wapcontent.title,count(*) from useraccesslog,wapcontent wh
ere Useraccesslog.contentId=Wapcontent.contentId and Useraccesslog.createdate >='2008-08-07 15:11:49' and User
accesslog.createdate <='2008-08-07 18:11:49' group by Useraccesslog.contentId order by count(*) desc]; nested
exception is org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before exe
cuting the query. [select distinct Wapcontent.title,count(*) from useraccesslog,wapcontent where Useraccesslog
.contentId=Wapcontent.contentId and Useraccesslog.createdate >='2008-08-07 15:11:49' and Useraccesslog.created
ate <='2008-08-07 18:11:49' group by Useraccesslog.contentId order by count(*) desc]
org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the qu
ery. [select distinct Wapcontent.title,count(*) from useraccesslog,wapcontent where Useraccesslog.contentId=Wa
pcontent.contentId and Useraccesslog.createdate >='2008-08-07 15:11:49' and Useraccesslog.createdate <='2008-0
8-07 18:11:49' group by Useraccesslog.contentId order by count(*) desc]
 at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:169)
 at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:140)
 at com.zrrt.wapportal.dao.hibernate.UseraccesslogDAOHibernate$1.doInHibernate(UseraccesslogDAOHibernate.java:
118)
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:329)
 at com.zrrt.wapportal.dao.hibernate.UseraccesslogDAOHibernate.getUseraccesslogsByCpAContent(UseraccesslogDAOH
ibernate.java:113)
 at com.zrrt.wapportal.service.impl.UseraccesslogManagerImpl.getUseraccesslogsByCpAContent(UseraccesslogManage
rImpl.java:69)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.ja
va:155)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
 at $Proxy13.getUseraccesslogsByCpAContent(Unknown Source)
 at com.zrrt.wapportal.webapp.action.GameProviderAction.getGameProvidersAccess(GameProviderAction.java:3140)
 at com.zrrt.wapportal.webapp.action.GameProviderAction.findGameProviderAccess(GameProviderAction.java:2984)
 at com.zrrt.wapportal.webapp.action.GameProviderAction.findGameProviderCpAccess(GameProviderAction.java:2801)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:302)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:170)
 at com.zrrt.wapportal.webapp.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.ja
va:56)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:115)
 at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:229)
 at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:199)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
 at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.zrrt.wapportal.webapp.filter.GZIPFilter.doFilter(GZIPFilter.java:51)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.zrrt.wapportal.webapp.filter.ActionFilter.doFilter(ActionFilter.java:119)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilte
r.java:174)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
 at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:84)
 at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:182)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java
:153)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.wrapper.ContextHolderAwareRequestFilter.doFilter(ContextHolderAwareRequestFilter.java
:50)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFil
ter.java:226)
 at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
 at net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
 at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
 at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:482)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
 at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.j
ava:665)
 at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
 at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
 at java.lang.Thread.run(Thread.java:595)

 

 当前的查询语句为:     String  sql ="select distinct Wapcontent.title,count(*) from useraccesslog,wapcontent where Useraccesslog.contentId=Wapcontent.contentId and Useraccesslog.createdate >='2008-08-07 15:11:49' and Useraccesslog.createdate <='2008-08-07 18:11:49' group by Useraccesslog.contentId order by count(*) desc";
                       SQLQuery query = session.createSQLQuery(sql)

 

 

解决方案:

     
         List temp = (List) getHibernateTemplate().execute(new HibernateCallback() {   
            public Object doInHibernate(Session session) throws HibernateException,SQLException {   
                   try {   
                   String  sql ="select distinct Wapcontent.title,count(*) from useraccesslog,wapcontent where Useraccesslog.contentId=Wapcontent.contentId and Useraccesslog.createdate >='2008-08-07 15:11:49' and Useraccesslog.createdate <='2008-08-07 18:11:49' group by Useraccesslog.contentId order by count(*) desc";
                       SQLQuery query = session.createSQLQuery(sql).addScalar("Wapcontent.title", new org.hibernate.type.StringType()).addScalar("count(*)", new IntegerType());   
                       return query.list();   
                   } catch (RuntimeException e) {   
                       log.error("query sql catch exception: " , e);   
                       throw e;   
                   }   
            }
        });    

参考: http://topic.csdn.net/u/20080716/14/0e5c4a21-352d-4b2b-bbdb-d09756aff3a3.html 

及 http://www.javaeye.com/topic/24713

  1. StringBuffer queryStr = new StringBuffer();   
  2. queryStr.append("select count(*) AA,");   
  3. queryStr.append("sum(st.num1) BB,sum(st.num2) CC,");   
  4. queryStr.append("max(st.cost1) DD,min(st.cost2) EE,");   
  5. queryStr.append("st.col1 FF from TBXXX st")   
  6. .append(" where ")   
  7. .append(SQLQuerySetup.createfilterStr(filter))   
  8. .append(" group by st.col1");   
  9.   
  10. query = session.createSQLQuery(queryStr.toString());   
  11. query.addScalar("AA"new org.hibernate.type.IntegerType());   
  12. query.addScalar("BB"new org.hibernate.type.IntegerType());   
  13. query.addScalar("CC"new org.hibernate.type.IntegerType());   
  14. query.addScalar("DD"new org.hibernate.type.IntegerType());   
  15. query.addScalar("EE"new org.hibernate.type.IntegerType());   
  16. query.addScalar("FF"new org.hibernate.type.IntegerType());   
  17. return query.list();  


 

你可能感兴趣的:(sql,exception,session,String,query,nested)